当前位置:网站首页>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 .
边栏推荐
- MySQL ERROR 1040: Too many connections
- Use xtrabackup for MySQL database physical backup
- 第一篇博客
- 简单解决phpjm加密问题 免费phpjm解密工具
- MySQL27-索引優化與查詢優化
- Record the first JDBC
- Time complexity (see which sentence is executed the most times)
- 16 medical registration system_ [order by appointment]
- 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?
- MySQL23-存储引擎
猜你喜欢

基于Pytorch的LSTM实战160万条评论情感分类

PyTorch RNN 实战案例_MNIST手写字体识别

How to make shell script executable

Mysql30 transaction Basics

MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?

软件测试工程师必备之软技能:结构化思维

MySQL34-其他数据库日志

MySQL27-索引優化與查詢優化

A necessary soft skill for Software Test Engineers: structured thinking

UEditor国际化配置,支持中英文切换
随机推荐
Advantages and disadvantages of evaluation methods
基于Pytorch的LSTM实战160万条评论情感分类
MySQL27-索引优化与查询优化
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
MySQL31-MySQL事务日志
Super detailed steps to implement Wechat public number H5 Message push
Routes and resources of AI
软件测试工程师必备之软技能:结构化思维
MySQL learning diary (II)
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
Use of dataset of pytorch
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
Cmooc Internet + education
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
MySQL 29 other database tuning strategies
Chrome浏览器端跨域不能访问问题处理办法
Mysql32 lock
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?
MySQL26-性能分析工具的使用
Windchill configure remote Oracle database connection