What is the difference between MyISAM and InnoDB?

What is the difference between MyISAM and InnoDB?
1. Storage structure
MyISAM: Each MyISAM is stored as three files on the 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: It can create 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 a user operates a myisam table, select, update, delete, and insert statements will automatically lock the table. Insert new data at the end of the table.
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: supports full-text index of FULLTEXT type
InnoDB: does not support full-text index of FULLTEXT type, but innodb can use sphinx plug-in to support full-text index, and the effect is better.
8. Table primary key
MyISAM: Allows the existence of a table without any index and primary key. The index is the address of the row.
InnoDB: If no primary key or non-empty unique index is set, a 6-byte primary key (not visible to the user) is automatically generated. The data is part of the primary index, and the additional index stores the value of the primary index.
9. The specific number of rows in the
table MyISAM: saves the total number of rows in the table, if select count(*) from table; will directly take out the value.
InnoDB: The total number of rows in the table is not saved. If you use select count(*) from table; it will traverse the entire table, which consumes a lot of money. However, after adding the wehre condition, myisam and innodb handle the same way.
10. CURD operation
MyISAM: If you perform a large number of SELECTs, MyISAM is a better choice.
InnoDB: If your data performs a lot of INSERTs or UPDATEs, you should use InnoDB tables for performance reasons. DELETE is better than InnoDB in terms of performance, but when DELETE FROM table, InnoDB will not rebuild the table, but delete it line by line. If you want to clear a table with a large amount of data on innodb, it is best to use the truncate table command.
11. Foreign key
MyISAM: does not support
InnoDB: supports
Through the above analysis, InnoDB can basically be considered to replace the MyISAM engine, because InnoDB itself has many good features, such as transaction support, stored procedures, views, row-level locking, etc. Wait, in the case of a lot of concurrency, I believe that InnoDB's performance must be much stronger than MyISAM. In addition, any kind of table is not omnipotent. Only by selecting the appropriate table type for the business type can the performance advantages of MySQL be maximized. If it is not a very complex web application or a non-critical application, you can continue to consider MyISAM, and you can consider the specific situation.

Guess you like

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