当前位置:网站首页>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 .
边栏推荐
- MySQL33-多版本并发控制
- How to build an interface automation testing framework?
- Transactions have four characteristics?
- NLP routes and resources
- 好博客好资料记录链接
- MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
- Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
- Sichuan cloud education and double teacher model
- Cmooc Internet + education
- MySQL底层的逻辑架构
猜你喜欢
13 medical registration system_ [wechat login]
该不会还有人不懂用C语言写扫雷游戏吧
jar运行报错no main manifest attribute
Mysql27 - Optimisation des index et des requêtes
MySQL25-索引的创建与设计原则
13 医疗挂号系统_【 微信登录】
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
MySQL30-事务基础知识
15 医疗挂号系统_【预约挂号】
随机推荐
Pytoch LSTM implementation process (visual version)
Mysql33 multi version concurrency control
A necessary soft skill for Software Test Engineers: structured thinking
Preliminary introduction to C miscellaneous lecture document
Use of dataset of pytorch
If someone asks you about the consistency of database cache, send this article directly to him
ZABBIX introduction and installation
Ueeditor internationalization configuration, supporting Chinese and English switching
15 medical registration system_ [appointment registration]
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
评估方法的优缺点
该不会还有人不懂用C语言写扫雷游戏吧
Case identification based on pytoch pulmonary infection (using RESNET network structure)
MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
Windchill configure remote Oracle database connection
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
实现以form-data参数发送post请求
Mysql36 database backup and recovery
MySQL30-事务基础知识
PyTorch RNN 实战案例_MNIST手写字体识别