Comparison of three common storage engines in MySQL database

Source: Internet
Author: User
Data in MySQL is stored in files (or memory) using different technologies. Each of these technologies uses different storage mechanisms and indexing techniques, lock level and ultimately provide a wide range of different functions and capabilities. In MySQL, the storage engine of MySQL may be the most distinctive of all relational database products, not only can multiple storage engines be used at the same time, in addition, plug-ins are used between each storage engine and MySQL.

Because the features of various storage engines vary greatly, this article mainly describes how to select an appropriate storage engine to deal with different business scenarios.

MyISAM

Features
Transactions not supported: MyISAM storage engine does not support transactions. therefore, business scenarios requiring transactions cannot be used.
Table-level locking: the locking mechanism is table-level indexing, which can reduce the implementation cost of locking but also greatly reduce its concurrency performance.
Read/write blocking: Not only does MyISAM block write during write, but the Read itself does not block other reads.
Only cache indexes: MyISAM can use the key_buffer cache to greatly improve access performance and reduce disk I/O. However, this cache area only caches indexes instead of data.

Applicable scenarios
No transaction support (not supported)
Relatively low concurrency (locking mechanism problems)
Relatively few data changes (blocking problem)
READ-oriented
Data consistency requirements are not very high

Best practices
Index as much as possible (Cache mechanism)
Adjust the read/write priority to ensure that important operations are given priority based on actual needs.
Enable delayed insertion to improve writing performance in large batches
Try to write the insert data to the end in sequence to reduce blocking.
Break down large operations to reduce the blocking time of a single operation
Reduce the number of concurrency. in some high-concurrency scenarios, queuing mechanism is implemented through applications.
Making full use of Query Cache can greatly improve access efficiency for relatively static data.
MyISAM's Count is especially efficient only when scanning the whole table. actual data access is required for the count with other conditions.

InnoDB

Features
Good transaction support: supports four transaction isolation levels and multi-version read
Row-level lock: The full table scan will still be a table lock based on the index. pay attention to the impact of the gap lock.
Read/write blocking is related to the transaction isolation level.
Highly efficient caching: data can be cached as well as indexes.
The entire table and primary key are stored in clusters to form a balance tree.
All Secondary indexes save the primary key information.

Applicable scenarios
Requires transaction support (with good transaction features)
Row-level locking can adapt to high concurrency, but it is necessary to ensure that the query is completed through the index.
Scenarios with frequent data updates
High data consistency requirements
The memory size of the hardware device is large. the good cache capability of InnoDB can be used to improve memory utilization and minimize disk IO.

Best practices
The primary key should be as small as possible to avoid extra space burden on the Secondary index.
Avoid full table scan because table locks are used.
Cache all indexes and data as much as possible to improve response speed
When large volumes of small inserts, try to control the transaction by yourself instead of using autocommit for automatic commit.
Reasonably set the innodb_flush_log_at_trx_commit parameter value and do not excessively pursue security.
Avoid primary key update, because this will bring a lot of data movement

NDBCluster

Features
Distributed: The Distributed Storage Engine. it can be composed of multiple NDBCluster storage engines, which respectively store part of the overall data.
Transactions supported: like Innodb, transactions supported
It can be different from mysqld on one host: it can be separated from mysqld on an independent host, and then communicate with mysqld over the network.
Memory demand is huge: new versions of indexes and indexed data must be stored in memory, and all data and indexes of old versions must exist in memory

Applicable scenarios
High concurrency requirements
The response to a single request is not very critical
The query is simple and the filtering conditions are relatively fixed. each request has a small amount of data and you do not want to perform horizontal Sharding on your own.

Best practices
Make the query as simple as possible to avoid data transmission across nodes
To meet the computing performance of SQL nodes as much as possible. a larger cluster SQL node will obviously have redundant Data nodes.
Use the 10-ge network environment to connect nodes to reduce the latency of data transmission at the network layer.

Note: The above three storage engines are currently the mainstream storage engines, and other storage engines such as Memory, Merge, CSV, and Archive are rarely used, here we will not analyze them one by one.

The above is the comparison of the features of the three common storage engines of MySQL database _ MySQL content. For more information, please follow the PHP Chinese network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.