MySQL
  Home arrow MySQL arrow Page 7 - Storage Engine (Table Types)
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Storage Engine (Table Types)
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 46
    2004-08-02

    Table of Contents:
  • Storage Engine (Table Types)
  • Locking
  • Multi-Version Concurrency Control
  • Transactions
  • Bene
  • Deadlocks
  • Transactions in MySQL
  • Selecting the Right Engine
  • Practical Examples
  • Table Conversions
  • The Storage Engines
  • MyISAM Tables
  • Compressed MyISAM Tables
  • InnoDB Tables
  • Heap (In-Memory) Tables

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    IBM developerWorks
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Storage Engine (Table Types) - Transactions in MySQL


    (Page 7 of 15 )

    MySQL provides two transaction-safe storage engines: Berkeley DB (BDB) and InnoDB. Their specific properties are discussed in next section. Each one offers the basic BEGIN/COMMIT/ROLLBACK functionality. They differ in their supported isolation levels, locking characteristics, deadlock detection, and other features.

    AUTOCOMMIT

    By default MySQL operates in AUTOCOMMIT mode. This means that unless you’ve explicitly begun a transaction, it automatically executes each query in a separate transaction. You can enable AUTOCOMMIT for the current connection by running:

    SET AUTOCOMMIT = 1;

    Disable it by executing:

    SET AUTOCOMMIT = 0;

    Changing the value of AUTOCOMMIT has no effect on non-transaction-safe tables such as MyISAM or HEAP.

    Implicit commits

    Certain commands, when issued during an open transaction, cause MySQL to commit the transaction before they execute. Typically these are commands that make significant changes, such as removing or renaming a table.

    Here is the list of commands for which MySQL implicitly commits a transaction:

    • ALTER TABLE

    • BEGIN

    • CREATE INDEX

    • DROP DATABASE

    • DROP TABLE

    • RENAME TABLE

    • TRUNCATE

    • LOCK TABLES

    • UNLOCK TABLES

    As additional features are added to MySQL, it is possible that other commands will be added to the list, so be sure to check the latest available documentation.

    Isolation levels

    MySQL allows you to set the isolation level using the SET TRANSACTION ISOLATION LEVEL command. Unless otherwise specified, the isolation level is changed beginning with the next transaction.

    To set the level for the whole session (connection), use:

    SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED

    Here’s how to set the global level:

    SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE

    MySQL recognizes all four ANSI standard isolation levels, and as of Version 4.0.5 of MySQL, InnoDB supports all of them:

    • READ UNCOMMITTED

    • READ COMMITTED

    • REPEATABLE READ

    • SERIALIZABLE

    The default isolation level can also be set using the --transaction-isolation command-line option when starting the server or set via my.cnf.

    Mixing storage engines in transactions

    Transaction management in MySQL is currently handled by the underlying storage engines, not at a higher level. Thus, you can’t reliably mix tables stored in transactional engines (such as InnoDB and BDB) in a single transaction. A higher-level transaction management service may someday be added to MySQL, making it safe to mix and match transaction-safe tables in a transaction. Until then, don’t expect it to work.

    If you mix transaction-safe and non-transaction-safe tables (such as InnoDB and MyISAM) in a transaction, the transaction will work properly if all goes well. However, if a rollback is required, the changes to the non-transaction-safe table won’t be undone. This leaves the database in an inconsistent state that may be difficult to recover from (and renders the entire point of transactions moot).

    Simulating transactions

    At times you may need the behavior of transactions when you aren’t using a transac-tion-safe table. You can achieve something like transactions using MySQL’s LOCK TABLES and UNLOCK TABLES commands. If you lock the tables that will be involved in the transaction and keep track of any changes that you make (in case you need to simulate a rollback), you’ll have something equivalent to running at the serializable isolation level. But the process is kludgy and error prone, so if you really need transactions, we recommend using a transactional storage engine.

    Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

    Visit the O'Reilly Network http://www.oreillynet.com for more online content.

    More MySQL Articles
    More By O'Reilly Media


       · Where is figure 2-1?
       · We will look into this ASAP.
       · Fixed
       · I don't think, that this sentence is quite acurate"MVCC can be thought of as a...
     

       

    MYSQL ARTICLES

    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...
    - Creating the Blog Script for a PHP/MySQL Blo...

    SlickEdit




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway