Mysql innodb和myisam

Reprinted from http://www.jianshu.com/p/a957b18ba40d

 

What is the difference between MyISAM and InnoDB?

Transactions and row-level locks are the biggest difference between the two!

 

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 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. Read locks can be read at the same time, which will block subsequent write operations; write locks will block subsequent read and write operations. If a read operation is slow, the write will always wait.
InnoDB: Support for transactions and row-level locks is the biggest feature of innodb. Row-level locks have higher concurrency performance. When querying without index conditions, InnoDB uses table locks instead of row locks; row locks are locks for indexes, not records, so although records of different rows are accessed, if you use For the same index key, lock conflicts will occur; even if the index field is used in the condition, whether to use the index to retrieve data is determined by MySQL by judging the cost of different execution plans. If MySQL thinks that the full table scan is more efficient. High, for example, for some very small tables, it will not use indexes, in which case InnoDB will use table locks instead of row locks

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 plugin 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-null 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, but after adding the wehre condition, both myisam and innodb handle the same way.

10. CURD operation

MyISAM: MyISAM is a better choice if doing a lot of SELECTs.
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 re-create 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 keys

MyISAM: not supported
InnoDB: supported

Guess you like

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