Introduction to MySQL storage engine

1. Introduction to MySQL database engine

The biggest difference between MySQL and other databases is that it is a plug-in storage system. The advantage of a storage engine is that each engine has its own characteristics, and different storage engine tables can be determined according to specific needs. During our use, if we are not satisfied with the performance of the storage engine, we can modify the source code according to the requirements to get the features we want. Of course, we can also write a storage engine ourselves.
Insert picture description here

2. The advantages and disadvantages of various engines

1. InnoDB storage engine

InnoDB is currently the default transactional engine of MYSQL and the preferred engine for transactional databases. It is currently the most important and most widely used storage engine. Support transaction security table (ACID), support row locking and foreign key.

The main features of InnoDB are:

  1. InnoDB provides MySQL with a transaction-safe storage engine with commit, rollback, and crash recovery capabilities. In SQL queries, you can freely mix InnoDB tables with other MySQL table types, even in the same query Can be mixed
  2. InnoDB is designed for maximum performance in processing huge amounts of data. In terms of CPU efficiency, most disk-based relational database storage engines are beyond the reach;
  3. InnoDB supports foreign key integrity constraints. When storing data in a table, the storage of each table is stored in the order of the primary key. If the primary key is not displayed when the table is defined, InnoDB will generate a 6-byte ROWID for each row, and Use this as the primary key;
  4. InnoDB achieves high concurrency through multi-version concurrency control, and has achieved 4 isolation levels (Read Uncommitted to read uncommitted content, Read Committed to read submitted content, Repeatable Read to be repeatable, Serializable to be serializable), and the Repeatable Read Repeatable read as the default level
  5. InnoDB is used in many large database sites that require high performance, and many companies have also proven its high availability, high performance, and high scalability.

Application scenarios:

Because InnoDB supports transaction processing, foreign keys, crash repair capabilities, and concurrency control features, it has high requirements for transaction integrity and concurrency control, such as bank operating systems and ticket sales. . . InnoDB has great advantages

2. MyISAM storage engine

Mainly for some OLAP (Online Analytical Processing) database applications, it was used as the default storage engine before MySQL 5.5.8 (except window). MyISAM does not support things, does not support table lock design, does not support full-text indexing, but it has higher insertion and query speed.

The main features of MyISAM are:

  1. MyISAM is non-transaction-safe;
  2. MyISAM is a table-level lock, and InnoDB is a row-level lock
  3. For MyISAM storage engine tables, MySQL values ​​cache index files, and the data files are completed by the operating system itself

Application scenarios:

If the table is mainly used to insert new records and read out records, then choosing MyISAM can achieve high processing efficiency, perform a large number of select operations, count operations, and do not need things.

3. NDB storage engine

The feature of NDB is that all data is stored in memory. Starting from MySQL 5.1, non-indexed data can be placed on disk. Therefore, the primary key search speed is very fast, and the database performance is linearly improved by adding NDB data storage nodes, which is high Available, high-performance cluster system.
But its join operation is completed in the MySQL database layer, so the query speed is very slow and requires huge network overhead.

4. Memory storage engine

Memory is to store the data in the table in memory. If the database crashes or restarts, the data is gone.

Main features of Meomory

  1. The Memory storage engine is very fast, but only supports table locks and has poor concurrency performance;
  2. MEMORY storage engine uses hash index by default, which is faster than using B-+Tree type. Of course, B-tree index can also be used.

Application scenarios:

Very suitable for using a temporary table for query in the database

5. Archive

Archive only supports insert and select operations, and indexes have been supported after MySQL 5.1. The Archive storage engine uses the zlib algorithm to achieve a compression ratio of 1:10. It has a good compression mechanism and is very suitable for storing archived data, so it is often used as a warehouse.

Main features of Archive

  1. Not a transaction-safe storage engine;
  2. Row locks are used to implement highly concurrent insert operations

Application scenarios:

Due to the high compression and fast insertion characteristics, Archive is very suitable as a storage engine for the log table, but the premise is that the table is not frequently queried.

6. Federated

Federated storage engine table does not store data, it points to a table on a remote MySQL database server, and it only supports MySQL database tables

Guess you like

Origin blog.csdn.net/weixin_46687295/article/details/106877117