当前位置:网站首页>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 .
边栏推荐
猜你喜欢

05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?

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

滑环安装有哪些技巧和方法

Solve the problem that stc8g1k08 program cannot run and port configuration

buuctf-pwn write-ups (6)

What are the skills and methods for slip ring installation

通过Rust语言计算加速技术突破图片识别性能瓶颈

Flink 实战问题(七):No Watermark(Watermarks are only available EventTime is used)

LeetCode 142. Circular linked list II

Bootstrapblazor + FreeSQL actual combat chart usage (2)
随机推荐
Kept to implement redis autofailover (redisha) 13
Solve the problem that only one line of text is displayed or not displayed in u8glib
Find the minimum value in the rotation sort array ii[classical Abstract dichotomy + how to break the game left, middle and right are equal]
memcached基础2
memcached基础1
光谱共焦如何测量玻璃基板厚度
Moher College -x-forwarded-for injection vulnerability practice
在线文本数字识别列表求和工具
Timing mechanism of LwIP
可视化介绍 Matplotlib 和 Plotnine
Buuctf PWN write UPS (6)
Keepalived 实现 Redis AutoFailover (RedisHA)12
Visual introduction to Matplotlib and plotnine
Esp32 add multi directory custom component
3线spi屏幕驱动方式
Other service registration and discovery
美团:踩雷好几年,才总结出的数据治理避坑攻略
Implementation of ARP module in LwIP
Kept to implement redis autofailover (redisha) 11
ArcGIS 镶嵌数据集切片丢失问题处理