Comparison of MySQL database MyISAM and InnoDB storage engines
MySQL has a variety of storage engines, MyISAM and InnoDB are two commonly used ones. Here are some basic concepts (not in-depth) about the two engines.
MyISAM is mysql 's default storage engine, based on the traditional ISAM type, supports full-text search, but is not transaction-safe, and does not support foreign keys. Each MyISAM table is stored in three files: the frm file stores the table definition; the data file is MYD (MYData); the index file is MYI (MYIndex).
InnoDB is a transactional engine that supports rollback, crash recovery capabilities, multi-version concurrency control, ACID transactions, and row-level locking (row locks of InnoDB tables are not absolute, if MySQL cannot determine the range to scan when executing a SQL statement , the InnoDB table will also lock the entire table, such as the SQL statement during the like operation), and provide a lock-free reading method consistent with the Oracle type. InnoDB stores its tables and indexes in a tablespace, which can contain several files.
Main difference:
- MyISAM is non-transaction-safe, while InnoDB is transaction-safe.
- The granularity of MyISAM locks is table-level, while InnoDB supports row-level locking.
- MyISAM supports full-text type indexes, while InnoDB does not support full-text indexes.
- MyISAM is relatively simple, so it is better than InnoDB in terms of efficiency. Small applications can consider using MyISAM.
- MyISAM tables are saved in the form of files, and using MyISAM storage in cross-platform data transfer will save a lot of trouble.
- InnoDB tables are more secure than MyISAM tables, and can switch non-transactional tables to transactional tables (alter table tablename type=innodb) without data loss.
Application scenarios:
- MyISAM manages non-transactional tables. 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 queries, MyISAM is a better choice.
- InnoDB is used for transaction processing applications and has numerous features, including ACID transaction support. If the application needs to perform a large number of INSERT or UPDATE operations, InnoDB should be used, which can improve the performance of multi-user concurrent operations.
Common commands:
(1) View the storage type of the table (three types):
- show create table tablename
- show table status from dbname where name=tablename
- mysqlshow -u user -p password --status dbname tablename
(2) Modify the storage engine of the table:
- alter table tablename type=InnoDB
(3) Add the following parameters to the command line to start the mysql database so that newly published tables use transactions by default:
- --default-table-type=InnoDB
(4) Temporarily change the default table type:
- set table_type=InnoDB
- show variables like 'table_type'