当前位置:网站首页>Mysql23 storage engine
Mysql23 storage engine
2022-07-06 10:33:00 【Protect our party a Yao】
One . View storage engine
- see mysql What storage engine is provided :
show engines;
show engines \G;
Two . Set the default storage engine of the system
- View the default storage engine :
show variables like '%storage_engine%';
# or
SELECT @@default_storage_engine;
- Modify the default storage engine
If the storage engine of the table is not explicitly specified in the statement creating the table , That will default to InnoDB As a storage engine for tables . If we want to change the default storage engine of the table , You can write the command line to start the server like this .
SET DEFAULT_STORAGE_ENGINE=MyISAM;
Or modify my.cnf file :
default-storage-engine=MyISAM
# Restart the service
systemctl restart mysqld.service
3、 ... and . Set the storage engine for the table
The storage engine is responsible for extracting and writing the data in the table , We can Different tables set different storage engines , In other words, different tables can have different physical storage structures , Different extraction and writing methods .
3.1. Specify the storage engine when creating the table
Our previous statements to create tables did not specify the storage engine of the table , Then the default storage engine will be used InnoDB . If we want to explicitly specify the storage engine of the table , It can be written like this :
CREATE TABLE Table name (
Create table statement ;
) ENGINE = Storage engine name ;
3.2. Modify the storage engine of the table
If the table has been built , We can also use the following statement to modify the storage engine of the table :
ALTER TABLE Table name ENGINE = Storage engine name ;
create table engine_demo_table(
c1 int primary key,
c2 varchar(25));
show create table engine_demo_table;
alter table engin_demo_table engine=MYISAM;
show create table engine_demo_table;
Four . Engine introduction
4.1. InnoDB engine : Transaction storage engine with foreign key support
- MySQL from 3.23.34a Start with InnoDB Storage engine . Greater than or equal to 5.5 after , By default InnoDB engine .
- InnoDB yes MySQL Of Default transactional engine , It's designed to handle a lot of short-term (short-lived) Business . It can ensure the complete submission of transactions (Commit) And rollback (Rollback).
- In addition to adding and querying , It needs to be updated 、 Delete operation , that , Preference should be given to InnoDB Storage engine .
- Unless there's a very special reason to use another storage engine , Otherwise, priority should be given to InnoDB engine .
- Data file structure :
- Table name .frm Storage table structure (MySQL8.0 when , Merge in table name .ibd in ).
- Table name .ibd Store data and index .
- InnoDB yes Designed for maximum performance in handling huge amounts of data .
- In previous releases , Dictionary data is stored as metadata files 、 Non transaction table, etc . Now these metadata files have been deleted . such as : .frm , .par , .trn , .isl , .db.opt Waiting MySQL8.0 There is no such thing as .
- contrast MyISAM Storage engine for , InnoDB The processing efficiency of writing is poor , And it will take up more disk space to save data and indexes .
- MyISAM Cache index only , Don't cache real data ;InnoDB Not only index but also real data , High memory requirements , And memory size has a decisive impact on performance .
4.2. MyISAM engine : The main non transactional storage engine
- MyISAM There are a lot of features , Include full text index 、 Compress 、 Space function (GIS) etc. , but MyISAM Unsupported transaction 、 Row-level locks 、 Foreign keys , There is no doubt that the defect is Can't recover safely after a crash .
- 5.5 The previous default storage engine .
- The advantage is access Fast , There is no requirement for transaction integrity or SELECT、INSERT Mainly applications .
- There is additional constant storage for data statistics . so count(*) The query efficiency is very high .
- Data file structure :
- Table name .frm Storage table structure .
- Table name .MYD Store the data (MYData).
- Table name .MYI Storage index (MYIndex).
- Application scenarios : Read only applications or read-only businesses .
4.3. Archive engine : For data archiving
- The following table shows ARCHIVE Storage engine functions
features | Support |
---|---|
B Tree index | I won't support it |
Backup / Time to recover ( Implement... In the server , Not in the storage engine ) | Support |
Cluster database supports | I won't support it |
Clustered index | I won't support it |
compressed data | Support |
Data caching | I won't support it |
Encrypt data ( The encryption function is implemented in the server ) | Support |
Foreign key support | I won't support it |
Full text search index | I won't support it |
Geospatial data types support | Support |
Geospatial index support | I won't support it |
Hash index | I won't support it |
The index buffer | I won't support it |
Lock granularity | Row lock |
MVCC | I won't support it |
Storage limits | No restrictions |
transaction | I won't support it |
Update the statistics of the data dictionary | Support |
4.4. Blackhole engine : Discard write operation , The read operation will return empty content
4.5. CSV engine : When storing data , Separate data items with commas
Use cases are as follows
create table testcsv (
i int not null,
c char(10) not null) engine=CSV;
INSERT INTO testcsv VALUES(1,'record one'),(2,'record two');
select * from testcsv;
cd /var/lib/mysql
cd MYSQLTEST/
4.6. Memory engine : Table in memory
summary :
Memory The logical medium used is Memory , Fast response , But when mysqld When the daemon crashes Data will be lost . in addition , The stored data is required to be in a format with constant data length , such as ,Blob and Text Data of type is not available ( Of variable length ).
Main features :
- Memory meanwhile Support hash (HASH) Indexes and B+ Tree index .
- Memory The watch is at least better than MyISAM Table One order of magnitude fast .
- MEMORY The size of the table is limited Of . The size of the table mainly depends on two parameters , Namely max_rows and max_heap_table_size . among ,max_rows You can specify... When creating a table ;max_heap_table_size The default size of is 16MB, It can be expanded as needed .
- Data files are stored separately from index files .
- shortcoming : Its data is easy to lose , Short life cycle . Based on this flaw , choice MEMORY You need to be very careful when storing the engine .
Use Memory Storage engine scenario : - The target data is relatively small , And very Frequent visits , Store data in memory , If the data is too large, it will cause out of memory . You can use the parameter max_heap_table_size control Memory The size of the table , Limit Memory The maximum size of the table .
- If The data is provisional , and Must be available immediately obtain , Then you can put it in memory .
- Stored in Memory If the data in the table suddenly If you lose it, it doesn't matter much .
4.7. Federated engine : Access remote tables
Federated The engine is accessing other MySQL One of the servers agent , Although the engine seems to provide a good Cross server flexibility , But it often brings problems , therefore It is disabled by default .
4.8. Merge engine : Manage multiple MyISAM A collection of tables made up of tables
4.9.NDB engine :MySQL Cluster specific storage engine
It's also called NDB Cluster Storage engine , It is mainly used for MySQL Cluster Distributed cluster Environmental Science , Be similar to Oracle Of RAC colony .
4.10. Engine comparison
MySQL In the same database , Different storage engines can be selected for different tables . The following table compares the common storage engines .
边栏推荐
- 颜值爆表,推荐两款JSON可视化工具,配合Swagger使用真香
- [C language] deeply analyze the underlying principle of data storage
- The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
- Vscode common instructions
- MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
- MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
- MySQL transaction log
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决
- Mysql32 lock
- 使用OVF Tool工具从Esxi 6.7中导出虚拟机
猜你喜欢
[C language] deeply analyze the underlying principle of data storage
What should the redis cluster solution do? What are the plans?
Adaptive Bezier curve network for real-time end-to-end text recognition
What is the current situation of the game industry in the Internet world?
【C语言】深度剖析数据存储的底层原理
Sichuan cloud education and double teacher model
高并发系统的限流方案研究,其实限流实现也不复杂
Introduction tutorial of typescript (dark horse programmer of station B)
PyTorch RNN 实战案例_MNIST手写字体识别
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
随机推荐
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
用于实时端到端文本识别的自适应Bezier曲线网络
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
MySQL29-数据库其它调优策略
What is the current situation of the game industry in the Internet world?
评估方法的优缺点
C miscellaneous two-way circular linked list
NLP routes and resources
Complete web login process through filter
MySQL real battle optimization expert 08 production experience: how to observe the machine performance 360 degrees without dead angle in the process of database pressure test?
15 医疗挂号系统_【预约挂号】
MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
Use xtrabackup for MySQL database physical backup
MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?
软件测试工程师必备之软技能:结构化思维
PyTorch RNN 实战案例_MNIST手写字体识别
Mysql35 master slave replication
MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
安装OpenCV时遇到的几种错误
MySQL transaction log