MySQL two storage engines: MyISAM and InnoDB summary

MyISAM is the default MySQL database engine (before version 5.5), by the early ISAM (Indexed Sequential Access Method: sequential access method index) are improved. Although the excellent performance, but there is a drawback: Does not support transaction processing (Transaction) . However, in the years of development, MySQL also introduced InnoDB (another database engine), in order to strengthen the referential integrity violations and concurrent processing mechanism, then gradually replaced by MyISAM.

InnoDB, is one of MySQL database engine, one of the standard binary release of MySQL AB. InnoDB was developed by Innobase Oy company, when in May 2006 by the merger of Oracle. Compared with the traditional ISAM and MyISAM, InnoDB is the most significant feature is the support of ACID-compliant transaction (Transaction) feature, similar to PostgreSQL. Currently InnoDB uses two-track authorization, one GPL license, and the other is a proprietary software license.

Between MyISAM and InnoDB has a significant difference, simply sort the following:
1) transaction support
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.

MyISAM non-transaction-safe, and InnoDB is transaction-safe, auto-commit is enabled by default, should the merger transaction, submitted together, reducing the overhead caused by multiple submissions database, greatly improving performance.

2) Memory
MyISAM: Each MyISAM storage into three files on disk. The name of the first file name of the table to begin the extension indicates the file type. .frm file stores the table. Extended data file named .MYD (MYData). Extension index file is .MYI (MYIndex).
InnoDB: all the tables are stored in the same data file (may be more than one file, or file a separate table space), the size of the InnoDB table is limited only to the size of the operating system files, usually 2GB.

3) storage
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.

4) portability, backup and restore
MyISAM: the data are stored as files, 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.

5) transaction support
MyISAM: it emphasizes that performance, every time the query is atomic, which performs several times faster than InnoDB type, but does not provide transaction support.
InnoDB: provides advanced database features Affairs supports transactions, foreign keys and so on. With a transaction (commit), transaction-safe rollback (rollback) and crash repair capacity (crash recovery capabilities) of (transaction-safe (ACID compliant)type table.

6) AUTO_INCREMENT
MyISAM: we can build together a joint index and other fields. Automatic growth engine of the column must be an index, if the index is a combination of automatic growth may not be the first column, he can be incremented according to the sort in earlier columns.
InnoDB: InnoDB must contain only the index of the field. Automatic growth engine of the column must be an index, if the index is a combination must also be the first column of the composite index.

7) table lock differences
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 end of the list to insert new 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
MyISAM: support (FULLTEXT type) full-text index
InnoDB: does not support full-text indexing (FULLTEXT type), but you can use sphinx innodb plugin supports full-text indexing and better.

Full-text index refers to the establishment of reverse-order index for char, varchar, and text for each word (except stop words). MyISAM full-text indexing is actually futile, because it does not support the Chinese word must be written by the user, and then add a space after the word data table, and less than 75 characters and words are the same as stop words are ignored.

Further, the index and data separation MyISAM, InnoDB together, non-clustered index MyISAM natural, up to the nature of a unique, InnoDB data file itself is the primary key index file, this index is called a "cluster index"

9) the primary key table
MyISAM: Allow any index table and not the presence of the primary key index is stored in the address line.
InnoDB: If no non-null primary key or unique index, will automatically generate a 6-byte main key (not visible to users), the data part of the main index, the index is stored an additional value of the main index. InnoDB larger primary key range is twice the maximum of MyISAM.

10) Specific table rows
MyISAM: number of rows with a stored table, if the select count (*) from table; this value will be taken directly.
InnoDB: no number of rows in the table to save (only traverse), if you use select count (*) from table; it will traverse the entire table, consumption is quite large, but added a condition after wehre, myisam and processing are the same way innodb .

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) Foreign key
MyISAM: does not support
InnoDB: Support

13) query efficiency
is not where the count (*) to use MyISAM is much 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, we can still continue to consider MyISAM, and this situation can own discretion.

Both MyISAM and InnoDB scenarios:
1) MyISAM manage non-transactional table. It provides high-speed storage and retrieval, as well as full-text search capabilities. If the application needs to perform a large number of SELECT query, MyISAM is a better choice.
2) InnoDB for transaction processing applications, it has a number of features, including ACID transaction support. If the application needs to perform a lot of INSERT or UPDATE operation, you should use InnoDB, which can improve the performance of multi-user concurrent operations.

But the actual scenario, the need for analyze specific issues, can follow the following general questions:
- Is there a database foreign keys?
- the need for transactional support?
- the need for full-text indexing?
- What kind of database query patterns often use? In the write once read many or few applications Innodb insert more stable, in the case of concurrent can basically, if the reading speed is relatively fast application requirements or selected MyISAM.
- how much data in the database? Large size tend to innodb, because the transaction log, fault recovery.

InnoDB, is one of MySQL database engine, one of the standard binary release of MySQL AB. InnoDB was developed by Innobase Oy company, when in May 2006 by the merger of Oracle. Compared with the traditional ISAM and MyISAM, InnoDB is the most significant feature is the support of ACID-compliant transaction (Transaction) feature, similar to PostgreSQL. Currently InnoDB uses two-track authorization, one GPL license, and the other is a proprietary software license.

Between MyISAM and InnoDB has a significant difference, simply sort the following:
1) transaction support
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.

MyISAM non-transaction-safe, and InnoDB is transaction-safe, auto-commit is enabled by default, should the merger transaction, submitted together, reducing the overhead caused by multiple submissions database, greatly improving performance.

2) Memory
MyISAM: Each MyISAM storage into three files on disk. The name of the first file name of the table to begin the extension indicates the file type. .frm file stores the table. Extended data file named .MYD (MYData). Extension index file is .MYI (MYIndex).
InnoDB: all the tables are stored in the same data file (may be more than one file, or file a separate table space), the size of the InnoDB table is limited only to the size of the operating system files, usually 2GB.

3) storage
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.

4) portability, backup and restore
MyISAM: the data are stored as files, 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.

5) transaction support
MyISAM: it emphasizes that performance, every time the query is atomic, which performs several times faster than InnoDB type, but does not provide transaction support.
InnoDB: provides advanced database features Affairs supports transactions, foreign keys and so on. With a transaction (commit), transaction-safe rollback (rollback) and crash repair capacity (crash recovery capabilities) of (transaction-safe (ACID compliant)type table.

6) AUTO_INCREMENT
MyISAM: we can build together a joint index and other fields. Automatic growth engine of the column must be an index, if the index is a combination of automatic growth may not be the first column, he can be incremented according to the sort in earlier columns.
InnoDB: InnoDB must contain only the index of the field. Automatic growth engine of the column must be an index, if the index is a combination must also be the first column of the composite index.

7) table lock differences
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 end of the list to insert new 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
MyISAM: support (FULLTEXT type) full-text index
InnoDB: does not support full-text indexing (FULLTEXT type), but you can use sphinx innodb plugin supports full-text indexing and better.

Full-text index refers to the establishment of reverse-order index for char, varchar, and text for each word (except stop words). MyISAM full-text indexing is actually futile, because it does not support the Chinese word must be written by the user, and then add a space after the word data table, and less than 75 characters and words are the same as stop words are ignored.

Further, the index and data separation MyISAM, InnoDB together, non-clustered index MyISAM natural, up to the nature of a unique, InnoDB data file itself is the primary key index file, this index is called a "cluster index"

9) the primary key table
MyISAM: Allow any index table and not the presence of the primary key index is stored in the address line.
InnoDB: If no non-null primary key or unique index, will automatically generate a 6-byte main key (not visible to users), the data part of the main index, the index is stored an additional value of the main index. InnoDB larger primary key range is twice the maximum of MyISAM.

10) Specific table rows
MyISAM: number of rows with a stored table, if the select count (*) from table; this value will be taken directly.
InnoDB: no number of rows in the table to save (only traverse), if you use select count (*) from table; it will traverse the entire table, consumption is quite large, but added a condition after wehre, myisam and processing are the same way innodb .

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) Foreign key
MyISAM: does not support
InnoDB: Support

13) query efficiency
is not where the count (*) to use MyISAM is much 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, we can still continue to consider MyISAM, and this situation can own discretion.

Both MyISAM and InnoDB scenarios:
1) MyISAM manage non-transactional table. It provides high-speed storage and retrieval, as well as full-text search capabilities. If the application needs to perform a large number of SELECT query, MyISAM is a better choice.
2) InnoDB for transaction processing applications, it has a number of features, including ACID transaction support. If the application needs to perform a lot of INSERT or UPDATE operation, you should use InnoDB, which can improve the performance of multi-user concurrent operations.

But the actual scenario, the need for analyze specific issues, can follow the following general questions:
- Is there a database foreign keys?
- the need for transactional support?
- the need for full-text indexing?
- What kind of database query patterns often use? In the write once read many or few applications Innodb insert more stable, in the case of concurrent can basically, if the reading speed is relatively fast application requirements or selected MyISAM.
- how much data in the database? Large size tend to innodb, because the transaction log, fault recovery.

Guess you like

Origin www.cnblogs.com/geogre123/p/10929961.html