当前位置:网站首页>30 MySQL tutorial MySQL storage engine overview
30 MySQL tutorial MySQL storage engine overview
2022-06-27 01:05:00 【Lonely city cool dream】
MySQL The database provides a unique plug-in storage engine , Common storage engines are InnoDB、MyISAM、NDB、Memory、Archive、Federated、Maria wait , And different storage engines have completely different functions , When creating a table, you can specify the type of storage engine , If you do not specify the storage engine type ,MySQL8.0 The default storage engine is InnoDB.
1. InnoDB Storage engine
InnoDB The biggest feature of the storage engine is that it supports transactions , It is mainly applied to transactions (OLTP) Related data storage . Its functional features are Row lock 、 Support foreign keys , And the general operation query will not generate locks .InnoDB Storage engine from MySLQ 5.5.5 Later versions are the default storage engine . InnoDB There is multi version concurrency control , And there are 4 Kind of isolation level , The isolation levels are Sequential reading (SERIALIZABLE)、 Repeatable (REPEATABLE READ)、 Read submitted (READ COMMITTED)、 Read uncommitted (READ UNCOMMITTED).
Let's create a table sql To create a new InnoDB Store engine type data tables :
CREATE TABLE `test` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '', `age` int(10) unsigned NOT NULL, `id_number` varchar(18) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `email` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;The results are shown in the following figure :

Tips: As shown in the figure above , among ENGINE=InnoDB Indicates that the storage engine type specified in the table creation is InnoDB.
2. MyISAM Storage engine
MyISAM The storage engine is MySQL 5.5.8 The storage engine used by default before version , It does not support transactions ,MyISAM The storage engine table consists of MYD and MYI form , among MYD A file used to store data ,MYI A file used to store indexes .
Let's create a table sql To create a new MyISAM Store engine type data tables :
CREATE TABLE `test_my` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '', `age` int(10) unsigned NOT NULL, `id_number` varchar(18) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `email` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;The results are shown in the following figure :
Tips: Be careful : about MyISAM Storage engine , MySQL The database only caches index files , The data file of the database is completed by the operating system .
3. NDB Storage engine
NDB The storage engine is a cluster storage engine , Its characteristic is that all data is stored in memory ( You can put non indexed data on disk ), The search speed through the primary key is very fast , NDB Table join operation of storage engine (JOIN) By MySQL Server Layers complete , Its execution speed is relatively slow . because NDB It's a cluster storage engine , It is not convenient to make a demonstration here .
4. MEMORY Storage engine
Memory The storage engine stores the data in the table in memory , If the database collapse (crash) Or restart , The data in the table will be lost .
Let's create a table sql To create a new MyISAM Store engine type data tables :
CREATE TABLE `test_memory` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '', `age` int(10) unsigned NOT NULL, `id_number` varchar(18) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `email` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=MEMORY AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;The results are shown in the following figure :

5. ARCHIVE Storage engine
ARCHIVE The storage engine only supports INSERT Insert and SELECT Inquire about operation , This means that the inserted data cannot be changed , therefore ARCHIVE Storage engines are great for storing archived data . Let's create a table sql To create a new ARCHIVE Store engine type data tables :
CREATE TABLE `test_archive` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '', `age` int(10) unsigned NOT NULL, `id_number` varchar(18) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `email` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=ARCHIVE AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;The results are shown in the following figure :

Tips: Be careful :ARCHIVE The storage engine uses row locks to achieve highly concurrent write operations , But it is not crash safe Storage engine for .
6. FEDERATED Storage engine
FEDERATED The storage engine does not store data , It points to the remote MySQL database . Only the organization information of the table is stored locally , The data is stored in the remote server through the remote connection , The operations of adding, deleting, changing, and querying are performed by accessing the remote database through the established connection , Return the result to the local .FEDERATED The storage engine is not enabled by default , You can check the startup status of all storage engines first :
SHOW ENGINES; The results are as follows :

Tips: if FEDERATED The storage engine is not enabled , Can be in MySQL In profile [mysqld] Add a line below federated, And then restart MySQL Can be opened .
Let's create a table sql To create a new FEDERATED Store engine type data tables :
CREATE TABLE `test_fed` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '', `age` int(10) unsigned NOT NULL, `id_number` varchar(18) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `email` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=FEDERATED CONNECTION='mysql://root:[email protected]:3306/sakila/actor';The results are shown in the following figure :

7. MARIA Storage engine
MARIA Storage engine is a relatively new storage engine , Is to replace the original MyISAM Storage engine , It can be understood as MyISAM Subsequent versions of the storage engine .MARIA The storage engine is characterized by supporting data and file indexing , The design of row lock is applied , Provides multi version concurrency control (MVCC), Support transactions .
8. CSV Storage engine
A storage engine that logically separates data by commas . It creates one for each data table in the database subdirectory .CSV file . This is a normal text file , Each data line takes up one text line .CSV The storage engine does not support indexes .
9. Summary
This section describes 8 Storage engine , MySQL There are many other storage engines available , for example Merge、Sphinx、Infobright, They have their own suitable application scenarios , Beginners learn more InnoDB Storage engine , InnoDB The storage engine is also the most frequently asked storage engine in the interview . This section simply introduces these storage engines , Learn the basics of the storage engine , For more in-depth knowledge of the storage engine, you need to read the underlying source code .
边栏推荐
- 数据库面试题+sql语句解析
- 3-wire SPI screen driving mode
- buuctf-pwn write-ups (6)
- 接口测试框架实战(一) | Requests 与接口请求构造
- Flink 实战问题(七):No Watermark(Watermarks are only available EventTime is used)
- 3線spi屏幕驅動方式
- Great vernacular with high concurrency (I)
- MySQL之账号管理、建库以及四大引擎+案例
- 统一结果集的封装
- Basic introduction to C program structure Preview
猜你喜欢

Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)

清华&智源 | CogView2:更快更好的文本图像生成模型

The world is very big. Some people tattoo QR codes on their necks

IIS 部署静态网站和 FTP 服务

Statistical Hypothesis Testing

JSON解析,ESP32轻松获取时间气温和天气

如何把老式键盘转换成USB键盘并且自己编程?

在线文本数字识别列表求和工具

ESP32-SOLO开发教程,解决CONFIG_FREERTOS_UNICORE问题
![Count the logarithm of points that cannot reach each other in an undirected graph [classic adjacency table building +dfs Statistics - > query set optimization] [query set manual / write details]](/img/cc/a0be58eddc72c22a9a6ee5c61eb81a.png)
Count the logarithm of points that cannot reach each other in an undirected graph [classic adjacency table building +dfs Statistics - > query set optimization] [query set manual / write details]
随机推荐
These 10 copywriting artifacts help you speed up the code. Are you still worried that you can't write a copywriting for US media?
xml学习笔记
这10款文案神器帮你速码,做自媒体还担心写不出文案吗?
Solve the problem that only one line of text is displayed or not displayed in u8glib
Unable to create a folder to save the sketch: MKDIR sketch
Kept to implement redis autofailover (redisha) 15
memcached基础3
memcached基础
Summary of working at home during the epidemic | community essay solicitation
buuctf-pwn write-ups (6)
3線spi屏幕驅動方式
Interface test framework practice (I) | requests and interface request construction
Keepalived 实现 Redis AutoFailover (RedisHA)17
Great vernacular with high concurrency (I)
统计无向图中无法互相到达点对数[经典建邻接表+DFS统计 -> 并查集优化][并查集手册/写的详细]
MySQL之账号管理、建库以及四大引擎+案例
Solve the problem that stc8g1k08 program cannot run and port configuration
Reading graph augmentations to learn graph representations (lg2ar)
其他服务注册与发现
Is it safe to open a securities account online? Is it reliable to speculate in stocks by mobile phone