The difference between innodb and myisam

Author: Oscarwin
Link: https://www.zhihu.com/question/20596402/answer/211492971
Source: Zhihu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization, for non-commercial reprint, please indicate the source.
 

the difference:

1. InnoDB supports transactions, but MyISAM does not. For InnoDB, each SQL language is encapsulated into a transaction by default and automatically submitted. This will affect the speed, so it is best to put multiple SQL languages ​​between begin and commit to form a transaction;

2. InnoDB supports foreign keys, but MyISAM does not. Converting an InnoDB table containing foreign keys to MYISAM will fail;

3. InnoDB is a clustered index, and the data file is tied to the index. It must have a primary key, and the efficiency of indexing through the primary key is very high. However, the auxiliary index requires two queries, the primary key is queried first, and then the data is queried through the primary key. Therefore, the primary key should not be too large, because if the primary key is too large, other indexes will also be large. And MyISAM is a non-clustered index, the data file is separated, and the index stores the pointer of the data file. Primary key indexes and secondary indexes are independent.

4. InnoDB does not save the specific number of rows in the table, and requires a full table scan when executing select count(*) from table. However, MyISAM uses a variable to save the number of rows in the entire table. When executing the above statement, you only need to read the variable, and the speed is very fast;

5. Innodb does not support full-text indexing, while MyISAM supports full-text indexing, and MyISAM has higher query efficiency;

 

how to choose:

1. Whether to support transactions, if so, please choose innodb, if not, you can consider MyISAM;

2. If most of the tables are only read queries, you can consider MyISAM. If both reads and writes are frequent, please use InnoDB.

3. After the system crashes, it is more difficult for MyISAM to recover, is it acceptable;

4. Starting from MySQL5.5, Innodb has become the default engine of Mysql (MyISAM before), which shows that its advantages are obvious to all. If you don't know what to use, then use InnoDB, at least it will not be bad.

Reposted from: https://www.zhihu.com/question/20596402

Guess you like

Origin blog.csdn.net/qq_21514303/article/details/89215285