Mysql storage engine introduction and selection

Mysql database common storage engine

Mysql database is an open source database that supports a variety of storage engine choices. For example, the most commonly used storage engines are: MyISAM, InnoDB, Memory, etc.

(1) MyISAM storage engine

MyISAM is the default storage engine of Mysql, it supports B-tree/FullText/R-tree index types, and the lock level of MyISAM is table lock, the overhead of table lock is small, and the lock is fast; the lock granularity is large, and the probability of lock conflict occurs Higher, the concurrency is low; table locks are suitable for queries. The MyISAM engine does not support transactionality, nor does it support foreign keys.

(2) InnoDB storage engine

The biggest highlight of the InnoDB storage engine is that it supports transactionality and rollback. It supports Hash/B-tree index types. The lock level of InnoDB is row lock. The consumption of row lock is greater than that of table lock. However, when the concurrent access volume of the system is high, the overall performance of InnoDB is much higher than that of MyISAM. InnoDB indexes not only cache the index itself, but also cache the data, so InnoDB requires more memory.

(3) Memory storage engine

The Memory storage engine is a memory-level storage engine that stores all data in memory, so the amount of data it can store is relatively small. And because of the characteristics of memory, the memory storage engine has poor support for data consistency. The lock level of Memory is the same as that of MyISAM, which is a table lock; and does not support transactionality.

 

 

How to choose the right storage engine

Using MyISAM engine

  • R/W > 100 : 1 and fewer Updates (R/W: read/write ratio)
  • Concurrency is not high, no need to support transactions
  • Small amount of table data
  • Full text search required

Using InnoDB engine

  • R/W is relatively small, and large fields are updated frequently
  • Table data volume exceeds 10 million, high concurrency
  • High security and availability requirements

Using Memory Engine

  • have enough memory
  • The requirements for data consistency are not high, such as session/online number, etc.
  • Data that needs to be archived regularly

 

Epilogue

   The choice of the database, the choice of the database storage engine, and the optimization of the database are like an art. There is no good or bad, only suitable and unsuitable. There are many factors that need to be considered in a project. How to weigh the weights between several factors and how to find an optimal solution really requires a long period of experience accumulation. The road to database learning is long. Persevere and persevere!

 

 

 

 

 

 

 

.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326220483&siteId=291194637