What is InnoDB and MyISAM in MySQL?

94,531

Solution 1

InnoDB and MYISAM, are storage engines for MySQL.

These two differ on their locking implementation: InnoDB locks the particular row in the table, and MyISAM locks the entire MySQL table.

You can specify the type by giving MYISAM OR InnoDB while creating a table in DB.

Solution 2

Have a look at

InnoDB and MyISAM

InnoDB is a storage engine for MySQL, included as standard in all current binaries distributed by MySQL AB. Its main enhancement over other storage engines available for use with MySQL is ACID-compliant transaction support

MyISAM is the default storage engine for the MySQL relational database management system versions prior to 5.5 1. It is based on the older ISAM code but has many useful extensions. The major deficiency of MyISAM is the absence of transactions support. Versions of MySQL 5.5 and greater have switched to the InnoDB engine to ensure referential integrity constraints, and higher concurrency.

Solution 3

They are storage engines.

http://dev.mysql.com/doc/refman/5.1/en/storage-engines.html

MyISAM: The default MySQL storage engine and the one that is used the most in Web, data warehousing, and other application environments. MyISAM is supported in all MySQL configurations, and is the default storage engine unless you have configured MySQL to use a different one by default.

InnoDB: A transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data. InnoDB row-level locking (without escalation to coarser granularity locks) and Oracle-style consistent nonlocking reads increase multi-user concurrency and performance. InnoDB stores user data in clustered indexes to reduce I/O for common queries based on primary keys. To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints.

Solution 4

InnoDB is a transactional storage engine of MySQL whereas MyISAM is a non-transactional storage engine. In other words, InnoDB follows the ACID properties to maintain the integrity of data but MyISAM doesn't follow ACID properties thus failing to maintain the integrity of the data.

In an InnoDB (transactional) table, the transactional changes can be easily undone if a rollback is required. But changes made to a MyISAM (non-transactional) table cannot be undone when rolling back a transaction is required.

For example, you want to transfer money from your checking account to saving account. This is done by a transaction which includes 5 queries.

1 START TRANSACTION;
2 SELECT balance FROM checking WHERE customer_id = 10233276;
3 UPDATE checking SET balance = balance - 200.00 WHERE customer_id = 10233276;
4 UPDATE savings SET balance = balance + 200.00 WHERE customer_id = 10233276;
5 COMMIT;

Suppose, the process crashes at step 4. If a InnoDB table was used here, a rollback would undo the changes and you are saved from the risk of losing money. Literally, the table is unaware of any crash as the changes will not be commited to the table unless step 5 is successfully executed.

But in the case of a MyISAM table, one cannot undo the transactional changes when a rollback is called or if there is a crash leading to the failure of the transaction. This means, if the transaction crashed at step 3, money will be deducted from your checking account. But money wouldnot have been added to your savings account.

Example courtesy: "High Performance MySQL: Optimization, Backups, and Replication" - Book by Arjen Lentz, Derek J. Balling, Jeremy Zawodny, Peter Zaitsev, and Vadim Tkachenko

Solution 5

I wanted to add that having ability to specify a specific storage engine per table is one of the key strengths of MySQL (besides easy of use and good performance with no tweaking). For all operations where transactions are needed, just stick with InnoDB. However, MyISAM can really speed things up when transactions are not needed in certain situations - and requires less disk space and RAM compared to InnoDB.

That said, InnoDB is getting better all the time:

InnoDB 1.1 Performance and Scalability Enhancements

Share:
94,531
user130561
Author by

user130561

Updated on July 25, 2020

Comments

  • user130561
    user130561 almost 4 years

    What is InnoDB and MyISAM in MySQL ?

  • user130561
    user130561 over 13 years
    So while we install MySQL do we need to specifically specify which storage engine to use as our MySQL database ?
  • user130561
    user130561 over 13 years
    can we use both storage engines at the same time for our database ?
  • user467801
    user467801 over 13 years
    As mentioned in my post, the default is MyISAM. If you want to use the features of a different storage engine such as INNODB, then yes you would need to specify. This is not done during install, rather it is done during initial table creation.
  • nano7
    nano7 about 13 years
    you can, because for each table you can define a different storage engine. another question is if you should. in the mysql documentation are some explanations about this topic.
  • Harsha
    Harsha over 7 years
    But as per this :- dev.mysql.com/doc/refman/5.7/en/storage-engines.html; Default engine is InnoDB.
  • SOFe
    SOFe about 6 years
    According to dev.mysql.com/doc/refman/5.5/en/storage-engine-setting.html: "The default engine is InnoDB as of MySQL 5.5.5 (MyISAM before 5.5.5)" So the default engine is now InnoDB. This answer was posted 16 days after the first general-availability release with InnoDB as the default engine ;)
  • Vadiraj S J
    Vadiraj S J over 4 years
    Clear and simple answer.
  • Ganesh Patil
    Ganesh Patil almost 3 years
    Cleared my doubt very well. Thanks a Lot !!
  • Steffi Keran Rani J
    Steffi Keran Rani J almost 3 years
    @Ganesh Patil Glad to help