Detailed explanation of the difference between MyISAM and InnoDB

MyISAM is MySQL's default database engine (before version 5.5), improved by the earlier ISAM (Indexed Sequential Access Method: Indexed Sequential Access Method). Although the performance is excellent, it has one disadvantage: it does not support transactions. However, under the development of the past few years, MySQL also imported InnoDB (another database engine) to strengthen the referential integrity and concurrency violation handling mechanism, and later gradually replaced MyISAM.

InnoDB, one of MySQL's database engines, is one of the standards for the release of binary for MySQL AB. InnoDB was developed by Innobase Oy, which was acquired by Oracle in May 2006. Compared with traditional ISAM and MyISAM, the biggest feature of InnoDB is that it supports ACID-compliant transaction (Transaction) functions, similar to PostgreSQL. At present, InnoDB adopts a dual-track licensing system, one is GPL licensing, and the other is proprietary software licensing.

What is the difference between MyISAM and InnoDB?

1. Storage structure

MyISAM: Each MyISAM is stored as three files on disk. The name of the first file begins with the name of the table, and the extension indicates the file type. .frm files store table definitions. Data files have the extension .MYD (MYData). Index files have the extension .MYI (MYIndex).
InnoDB: All tables are stored in the same data file (may be multiple files, or independent tablespace files). The size of the InnoDB table is only limited by the size of the operating system file, generally 2GB.

2. Storage space

MyISAM: It can be compressed, and the storage space is small. Three different storage formats are supported: static table (default, but note that there can be no spaces at the end of the data, it will be removed), dynamic table, compressed table.
InnoDB: requires more memory and storage, it builds its dedicated buffer pool in main memory for caching data and indexes.

3. Portability, Backup and Recovery

MyISAM: Data is stored in the form of files, so it is very convenient in cross-platform data transfer. Operations can be performed individually on a table during backup and restore.
InnoDB: Free solutions can be to copy data files, backup binlog, or use mysqldump, which is relatively painful when the amount of data reaches tens of gigabytes.

4. Transaction support

MyISAM: The emphasis is on performance, each query is atomic, and its execution is several times faster than the InnoDB type, but it does not provide transaction support.
InnoDB: Provides advanced database features such as transaction support transactions, foreign keys, etc. Transaction-safe (ACID compliant) tables with commit, rollback, and crash recovery capabilities.

5、 AUTO_INCREMENT

MyISAM: You can build a joint index with other fields. The auto-growth column of the engine must be an index. If it is a composite index, the auto-growth can not be the first column. It can be sorted and incremented according to the previous columns.
InnoDB: InnoDB must contain an index for this field only. The auto-increment column of the engine must be an index, and if it is a composite index, it must also be the first column of the composite index.

6. Differences in table locks

MyISAM: Only table-level locks are supported. When the user operates the myisam table, the select, update, delete, and insert statements will automatically lock the table. If the locked table satisfies the insert concurrency, you can insert a new table at the end of the table. The data.
InnoDB: Support for transactions and row-level locks is the biggest feature of innodb. Row locks greatly improve the new performance of multi-user concurrent operations. However, the row lock of InnoDB is only valid for the primary key of WHERE, and the WHERE of non-primary key will lock the whole table.

7. Full-text index

MyISAM:支持 FULLTEXT类型的全文索引
InnoDB:不支持FULLTEXT类型的全文索引,但是innodb可以使用sphinx插件支持全文索引,并且效果更好。

8、 表主键

MyISAM:允许没有任何索引和主键的表存在,索引都是保存行的地址。
InnoDB:如果没有设定主键或者非空唯一索引,就会自动生成一个6字节的主键(用户不可见),数据是主索引的一部分,附加索引保存的是主索引的值。

9、 表的具体行数

MyISAM:保存有表的总行数,如果select count(*) from table;会直接取出出该值。
InnoDB:没有保存表的总行数,如果使用select count(*) from table;就会遍历整个表,消耗相当大,但是在加了wehre条件后,myisam和innodb处理的方式都一样。

10、 CURD操作

MyISAM:如果执行大量的SELECT,MyISAM是更好的选择。
InnoDB:如果你的数据执行大量的INSERT或UPDATE,出于性能方面的考虑,应该使用InnoDB表。DELETE 从性能上InnoDB更优,但DELETE FROM table时,InnoDB不会重新建立表,而是一行一行的删除,在innodb上如果要清空保存有大量数据的表,最好使用truncate table这个命令。

11、 外键

MyISAM:不支持
InnoDB:支持
通过上述的分析,基本上可以考虑使用InnoDB来替代MyISAM引擎了,原因是InnoDB自身很多良好的特点,比如事务支持、存储 过程、视图、行级锁定等等,在并发很多的情况下,相信InnoDB的表现肯定要比MyISAM强很多。另外,任何一种表都不是万能的,只用恰当的针对业务类型来选择合适的表类型,才能最大的发挥MySQL的性能优势。如果不是很复杂的Web应用,非关键应用,还是可以继续考虑MyISAM的,这个具体情况可以自己斟酌。


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324606835&siteId=291194637