The difference between two storage database engine is MyISAM and InnoDB

The difference between MyISAM and InnoDB

Overview: The default storage engine in previous versions of the database in MySQL5.5 for MyISAM, despite the good performance of MyISAM, but the disadvantage is that it does not support transactions, was later replaced by InnoDB.
I use mysql 5.5 version of the default installation is InnoDB, said the online version 5.5 is free installation MyISAM

(1) Services

MyISAM does not support transactions, while InnoDB support. The InnoDB AUTOCOMMIT is enabled by default, i.e., each SQL statement default is packaged into a transaction, automatically submitted, this will affect the speed, so it is best to display multiple SQL statements placed between the begin and the commit, a transaction consisting of to submit.

(2) Memory

MyISAM physical storage structure:
.frm definition table storage is
.myd data table is stored
.myi index table is stored in
the structure of the physical storage InnoDB:
exclusive table:
.frm table is stored defined
.ibd stored table data is exclusive
shared table:
.ibdata shared data stored in the table

(3) storage space

MyISAM: can be compressed, less storage space. Supports three different storage formats: static tables (default, but note that the data can not have spaces at the end, will be removed), dynamic table, compressed table.
InnoDB: requires more memory and storage, it will create its own dedicated buffer pool for caching data and indexes in main memory.

Backup and recovery (4) data

MyISAM: data is stored as a file, it will be very convenient for data transfer across the platform. It can be operated separately for a table at the time of backup and recovery.
InnoDB: free program can copy data files, backup binlog, or use mysqldump, the amount of data on tens of G when relatively painful.

Support (5) transactions

MyISAM query operations are atomic, but the transaction is not supported, the speed of execution is faster than InnoDB
InnoDB: supports advanced database features and other key external affairs. With a transaction (commit), transaction-safe rollback (rollback) and crash repair capacity (crash recovery capabilities) of (transaction-safe (ACID compliant) ) type table.

(6) Automatic growth

MyISAM for self-growth provision must be indexed, if the joint index, then the increment of the column may not be the first column of
the automatic growth column InnoDB must be indexed, if the joint index, then increment columns must also be in first row.

(7) table lock gap

MyISAM: supports only table-level locking, user myisam in the operation table, select, update, delete, insert statements are automatically locked to the table, in the case of concurrent insert table meet later if locked, you can insert a new table at the end of The data.
InnoDB: supports transactions and row-level locking is the most significant feature of innodb. Row lock greatly improve the multi-user concurrent operation of new energy. However, InnoDB row lock, except the primary key in the WHERE is an effective, non-primary key in the WHERE will lock the whole table.

MyISAM is table-level locking granularity, while InnoDB supports row-level locking. Is simply, InnoDB support data line lock, line lock and MyISAM does not support, support only lock the entire table. That MyISAM read and write locks on the same table are mutually exclusive, when MyISAM concurrent read and write in both the waiting queue if there are write requests a read request, the default write request high priority, even if the request is first to read, so MyISAM is not suitable for a large number of query and modify the coexistence of the situation, as long inquiry process will be blocked. Because MyISAM table is locked, so an operation is time-consuming read the writing process will starve other.

(8) full-text index

InnoDB does not support full-text indexing (sphinx plug-in can support full-text index, the better), MyISAM supports full-text indexing

(9) the primary key table

InnoDB: If the primary key and index table is empty, then will have their own hidden a 6-byte primary key
MyISAM: can no primary keys and indexes in the table

Specific number of rows (10) of the table

MyISAM: There are tables stored in a specific number of rows
InnoDB storage table in no specific number of rows, query time to traverse the entire table, consuming enormous.

(11) CURD operation

MyISAM: If you perform a lot of SELECT, MyISAM is a better choice.
InnoDB: If you perform a large number of data INSERT or UPDATE, for performance reasons, you should use InnoDB tables. DELETE from InnoDB performance better, but DELETE FROM table, InnoDB will not re-establish the table, but deleted line by line, on the innodb If you want to save a large number of empty tables of data, it is best to use truncate table command.

(12) a foreign key

MyISAM does not support foreign keys, InnoDB foreign keys support.

(13) query efficiency

Not where the count () use MyISAM faster than InnoDB. Because MyISAM built-in counter, when the count () which read directly from the counter, and InnoDB must scan the entire table. So execution count () on InnoDB generally accompanied where, and where to include in the index column other than the main key. Why here special emphasis on "other than primary key"? Since the primary index InnoDB and raw data are stored together, while the secondary index is stored separately, then there is a pointer to the primary key. So just count (), then use the secondary index scan faster, but mainly in the primary key index scan at the same time to return a greater role when the raw data. MyISAM is relatively simple, so the efficiency is better than InnoDB, a small application, consider using MyISAM.

Through the above analysis, basically consider using InnoDB instead of MyISAM engine, InnoDB itself because a lot of good features, such as transaction support, stored procedures, views, row-level locking, and so, in many cases concurrently, believe InnoDB MyISAM performance certainly better than a lot stronger. In addition, any kind of table is not a panacea, only the right to choose the right type of business for the table type used to play the greatest performance advantage of MySQL. If it is not very complex Web applications, non-critical applications, you can still continue to consider MyISAM, and this situation can consider yourself

Published 171 original articles · won praise 386 · views 160 000 +

Guess you like

Origin blog.csdn.net/weixin_42837024/article/details/102799479