当前位置:网站首页>MySQL series: storage engine

MySQL series: storage engine

2022-06-23 15:24:00 yue_ xin_ tech

Introduce

In the last article mysql General overview We probably know mysql Architecture design , It says Storage engine . It's in mysql Is a very important role in , Responsible for the creation of data 、 Read and update , That's the data I/O operation .

most important of all , It is Pluggable Module , This means that when we switch storage engines , For upper layer applications , There is no need to do any adaptation .

There are many kinds of storage engines , And they all have their own characteristics , Like the usual InnoDB Have transaction support 、MyISAM Fast, etc .

Usage of storage engine

As a plug-in module , We can naturally add 、 Uninstall the storage engine , And specify the storage engine when creating the table .

Load the storage engine

mysql Through defined API Interface to communicate with the storage engine , So we just need to implement the corresponding API Interface , You can go to mysql Load in at run time .

stay mysql There is one in the source code example Storage engine for , We can see what it needs to achieve API The interface is as follows :

 Storage engine interface

When we implement these methods , You can compile it into a shared library , Then load it in with the following statement

INSTALL PLUGIN example SONAME 'example.so';

It should be noted that , The plug-in file must be located in mysql Plug in directory , And have the right to plugin Tabular INSERT jurisdiction .

Uninstall the storage engine

To uninstall the storage engine , It's simpler

UNINSTALL PLUGIN example;

When uninstalled , The corresponding table will inaccessible , So be sure to pay attention to whether there are still tables of the storage engine in use !

View and use the storage engine

When we load the storage engine , You can use the following command to view :

show engines;

If we want to use the corresponding storage engine , You can use the following method :

  • Specify... When creating a table :CREATE TABLE t1 (id INT) ENGINE = INNODB;
  • Set default usage :SET default_storage_engine=INNODB;
  • Specify when modifying a table :ALTER TABLE t ENGINE = InnoDB;

among ALTER TABLE The old table will be copied to the new table , And it will be locked during this period , Pay special attention to .

Types and characteristics of storage engines

stay mysql There are many kinds of storage engines implemented in , Each storage engine has its own characteristics . Let's see mysql What are the supported storage engines in .

InnoDB: It is mysql The default storage engine for , Can achieve ACID Characteristic transactions , And can submit 、 Roll back 、 Restore data , It can well protect user data . Row level locks are also supported 、 Clustered indexes and foreign key constraints , Is a perfect storage engine .

MyISAM: yes mysql The initial storage engine , Small footprint , Can quickly store , Transaction is not supported , Provides lock granularity based on table level , For applications with configuration or read-only functionality .

Memory: The data is stored in memory , Can provide fast access , However, fewer people should use , After all, once the power is off, the data will be lost .

CSV: Text file with comma separated values , No index exists . But the compatibility is very good , You can exchange data with other programs .

Other storage engines use less , I won't mention ,

Differences between storage engines

Storage engines have their own characteristics , Their differences can be roughly summarized as follows :

  • concurrency : The granularity control of locks is different , Some provide table locks , Some provide row locks , Some even provide snapshot reading .
  • Business : Some storage engines support , Some don't support , Not every program design requires transactions , Pipelined data such as logs is not needed .
  • Referential integrity : That is, whether foreign keys are supported , With foreign keys , It is highly correlated , Association check will be performed when deleting .
  • storage : The storage methods of tables and indexes are different , image MyISAM Will be stored in three files ,InnoDB All tables are stored in the same data file .
  • Index support : There are clustered indexes , Store data directly on the leaf node , Some leaf nodes only store pointers to data areas .

summary

The plug-in storage engine brings us a variety of options , There are no rules for which storage engine to use , It can only be selected according to the current demand analysis . Like you want a full-text index , You can choose MyISAM or InnoDB, Want data integrity or transaction support , You need to choose InnoDB.

Of course , Many times, we will directly choose the default storage engine InnoDB, After all, in the face of Internet projects that will change their needs at any time , Big and full is our best choice .


Interested friends can search the official account 「 Read new technology 」, Pay attention to more push articles .
If you can , Just like it by the way 、 Leave a message 、 Under the share , Thank you for your support !
Read new technology , Read more new knowledge .
 Read new technology

原网站

版权声明
本文为[yue_ xin_ tech]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231438380757.html