MySQL tuning series (3) - the choice of storage engine

1. What is a storage engine

The data in a relational database exists in a table. A table can be understood as a table composed of rows and columns, which is similar to an Excel spreadsheet. Each table is a piece of data.
While storing data, tables also organize the storage structure of data, and the organizational structure of these data is determined by the storage engine.
That is, the role of the storage engine is to specify the storage structure for data storage, and the business directly determines the choice of the storage engine . Because different businesses have different requirements for data, such as queries, additions and deletions, foreign keys, transactions, indexes, etc.
Mysql checks the supported storage engine statement: show engines;
insert image description here
it can be seen that mysql supports InnoDB indexes by default, and supports transactions, row-level locks, and foreign keys.
The usage level of the storage engine is the data table.
The sql statement to switch the storage engine is as follows:

alter table a engine = innodb;

Second, the choice of storage engine

There are three commonly used storage engines for mysql:

Innodb: row (record) lock, transaction (rollback), foreign key
Myisam: table lock, full-text index
Memory: memory storage engine, fast speed, easy to lose data

1、Innodb

The default storage engine of mysql supports transactions and foreign keys.
Scenario: There are relatively high requirements for the integrity of transactions, and data consistency is required under concurrent conditions. In addition to inserting and querying, data operations also include many update and delete operations. ( general business, web )

2、Myisam

Table lock, full-text index, fast access.
Scenario: The application is mainly read and insert operations, with only a few update and delete operations, and the requirements for transaction integrity and concurrency are not very high. ( more reads and less writes, less demanding on data recovery, such as data warehouses )—MongoDB

3、Memory

Store all data in memory, with fast access speed, usually used for temporary tables and caches. The disadvantage of MEMORY is that there is a limit on the size of the table. Too large a table cannot be cached in memory, and data security cannot be guaranteed. —Redis

In general, Innodb is used by default, which can satisfy most scenarios.
Try not to mix storage engines, because there will be uncontrollable problems, such as:
transaction: a transaction operates on the tables of two storage engines. If the transaction is rolled back, the table of the InnoDB storage engine can be rolled back, and the data in the MyISAM storage engine table cannot be rolled back. This will bring some data logic problems.

Guess you like

Origin blog.csdn.net/liwangcuihua/article/details/130554963