The difference between InnoDB and MyISAM

The difference between InnoDB and MyISAM

 

1. Storage structure

MyISAM: The index and data files are stored separately, and each MyISAM is stored as three files on disk.

InnoDB: Indexes and data are tied together, all tables are stored in the same data file (may be multiple files, or independent tablespace files), the size of InnoDB tables 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. Static table, 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 Recovery

MyISAM: Data is stored in the form of files, which is convenient for cross-platform porting.

InnoDB: To back up data into .sql files, it will be troublesome if the amount of data is large.

 

4. Transaction Support

MyISAM: Does not support transactions, because high performance is required, each query is atomic, faster than InnoDB.

InnoDB: Supports transactions, foreign keys, and crash recovery.

 

5. auto_incremant

 

6. Lock

MyISAM: table lock. 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, new data can be inserted at the end of the table.

InnoDB: row lock, which greatly improves 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. Lock the index, not the data.

 

7. Full-text indexing

MyISAM: supports full-text indexing.

InnoDB: Full-text indexing is not supported, but innodb can use the sphinx plugin to support full-text indexing, and it works better.

 

8. Primary key

MyISAM: No index and primary key can be allowed, and the index is the storage address.

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

 

9. 表的具体行数

MyISAM:记录表的行数,select count(*) 时会直接取出记录。

InnoDB:不记录表的行数,select count(*) 时会遍历所有表。

 

10. 增删改查

MyISAM:如果执行大量的select,用MyISAM会更好。

InnoDB:如果大量insert、update,应考虑InnoDB;至于删除InnoDB也更好,但DELETE FROM table时,InnoDB不会重新建立表,而是一行一行的删除,在innodb上如果要清空保存有大量数据的表,最好使用truncate table这个命令。

 

11. 外键

MyISAM:不支持

InnoDB:支持

 

 

 

 

 

 参考:

http://www.jb51.net/article/62457.htm

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326592536&siteId=291194637