当前位置:网站首页>Mysql database: storage engine
Mysql database: storage engine
2022-06-29 22:44:00 【Full stack programmer webmaster】
One 、 What is a storage engine :
The storage engine is MylSQL At the heart of , yes data Library underlying software organization , The database is created using the storage engine 、 Inquire about 、 Update and delete data . Different storage engines provide different storage mechanisms 、 Indexing techniques 、 Lock level 、 Functions such as transaction . The storage engine is table based , Not databases .
Two 、 Common storage engines :
1、InnoDB Storage engine :
InnoDB yes MySQL5.5 The default storage engine after version , It is designed to achieve maximum performance in processing huge amounts of data , Its CPU Efficiency may be unmatched by any other disk based relational database engine lock .
InnoDB Support transactions 、 Provide row level locks , The primary key of each table cannot be empty and supports primary key self growth , Support for foreign key integrity constraints ;
2、MyISAM Storage engine :
Unsupported transaction 、 Foreign keys are also not supported , Use table level locks to control concurrent read and write operations , Full text index support .MyISAM The engine emphasizes fast read operations , Mainly used for high load select, Applications that do not require transaction integrity can use this engine to create tables .
MyISAM Types of tables support three different storage structures : Static type 、 Dynamic 、 Compression type :
(1) Static type : The size of the defined table column is fixed ( That is, it does not contain :xblob、xtext、varchar Data types with variable length ). The performance of tables using static format is higher , Because when maintaining and accessing data stored in a predetermined format , The cost is relatively low , But this high performance comes at the cost of space , Because it is fixed at the time of definition , So no matter how big the value in the column is , Will be subject to the maximum , Takes up the whole space . Advantages storage is very fast , Easy to cache , It's easy to recover in case of failure ; The disadvantage is that it usually takes up more space than a dynamic table .
(2) Dynamic : If the column is defined as dynamic (xblob, xtext, varchar And so on ), At this time MyISAM Automatically use dynamic , Although dynamic tables take up less space than static tables , But it brings performance degradation , Because if the content of a field changes , Then its position is likely to need to be moved , This will lead to debris , As the data changes , The amount of debris increases , Data access performance will be reduced .
For the problem of reducing data accessibility due to increased fragmentation , There are two solutions : ① Use static data types whenever possible ; ② Regular use optimize table table_name Statement to defragment a table , Recover space loss caused by updating and deleting table data . If the storage engine does not support optimize table table_name You can dump and reload the data , This also reduces fragmentation ;
(3) Compression type : If you create a read-only table in the database for the entire life cycle , Should be used MyISAM Compressed tables to reduce space consumption , Because each record is compressed individually , So there's only a very small cost of access .
3、Memory Storage engine :
Memory The storage engine stores data by creating temporary tables in memory . Each table actually corresponds to a disk file , The file name and table name are the same , The type is .frm. The disk file only stores the structure of the table , The data is stored in memory , So tables using this engine have extremely high inserts 、 Update and query efficiency . Because the stored data is stored in memory , If mysqld Process exception 、 Rebooting or shutting down the computer will cause the data to disappear .
By default Hash Indexes , You can also use B Tree index .
Memory The storage engine is mainly used for infrequently changing content , Or as an intermediate result table for statistical operations , It is convenient to analyze the intermediate results efficiently and get the final statistical results .
4、Archive Storage engine :
Archive The engine provides a good compression mechanism , It USES zlib Compression library , The compression ratio is very high , And it has high insertion speed , Support insert、replace and select operation , But does not support update、delete, Unsupported transaction , Index is not supported either (5.5 Indexing is supported after version ), So the query performance is poor , So it is suitable for warehouse use and data archiving , Store a large number of independent 、 Data as a historical record , Such as recording log information , Because they are not often read .
5、Merge Storage engine :
Merge The storage engine will be a certain number of MyISAM Tables with exactly the same table structure are combined into a whole ,Merge The table itself has no data , Yes Merge Types of tables can be queried , to update , Delete operation , These operations are actually internal MyISAM Table .
6、Berkeley Storage engine :(BDB)
The storage engine supports COMMIT and ROLLBACK And so on , Support page level lock . The engine includes MySQL 5.1 And above databases no longer support .
7、CSV(Comma-Separated Values Comma separated values )
A storage engine that logically separates data by commas . Using the engine MySQL The database table will be in MySQL The installation directory data Create a directory in the folder with the same database name as the table .CSV file ( therefore , It can be CSV Files of type are processed as tables ), This file is a normal text file , Each data line takes up one text line . This type of storage engine does not support indexes , That is, there is no primary key column in this type of table ; In addition, fields in the table are not allowed to be null.
8、Federated:
The storage engine can put different Mysql The servers Unite , Logically make up a complete database . It is very suitable for distributed database applications .
9、Cluster/NDB:
Highly redundant storage engine , The storage engine is used for multiple data machines to jointly provide services to improve overall performance and security . Suitable for large amount of data 、 Scenarios with high security and performance requirements .
10、BLACKHOLE( Black hole engine )
The storage engine supports transactions , And support mvcc Row level lock of , Any data written to this engine table disappears , It is mainly used for the relay storage of log recording or synchronous archiving , This storage engine has no special purpose , Otherwise, it is not suitable for use .
11、PERFORMANCE_SCHEMA:
The engine is mainly used to collect database server performance parameters . This engine provides the following functions : Provide details of the process waiting , Including locks 、 Mutex variables 、 file information ; Save historical event summary information , To provide MySQL Make detailed judgment on server performance ; It is very easy to add or delete monitoring event points , And can change at will mysql Monitoring cycle of the server , for example (CYCLE、MICROSECOND).
3、 ... and 、MyISAM And InnoDB The difference between storage engines :
1、 Transaction support :MyISAM Transaction not supported ,InnoDB Support transaction processing .
2、 Lock level :MyISAM Only table level locks are supported ,InnoDB Row level lock and table level lock are supported , Line level lock is used by default , however InnoDB The row lock of is realized by locking the index entries , That is, only query data through the index ,InnoDB To use row level locks , Otherwise, the watch lock will be used . Row level locks consume more resources than table locks every time they acquire and release locks . Using row locks may lead to deadlock , But there is no deadlock in table level lock .
3、 Table primary key and foreign key constraints :
(1)MyISAM: Allows tables without any indexes and primary keys to exist . Foreign key not supported .
(2)InnoDB: The primary key self growth column is supported, and the primary key cannot be empty , If no primary key or non empty unique index is set , It will automatically generate one 6 The primary key of the byte ( The user is not visible ). Support for foreign key integrity constraints .
4、 Index structure :MyISAM and InnoDB Is to use B+ Tree index ,MyISAM Of primary and secondary indexes Data Fields are the addresses where rows are saved , however InnoDB The primary key index of does not store the address of the row , Instead, save all the data of the row , And the secondary index Data The field holds the value of the primary index .
5、 Full-text index :MyISAM Support FULLTEXT Full-text index of type ,InnoDB Full text indexing is not supported (5.6 After the version InnoDB The storage engine began to support full-text indexing )
6、 Storage structure :
(1)MyISAM It will be stored in three files on disk .
- .frm: Storage table definition
- .MYD: Store the data
- .MYI: Storage index
(2)InnoDB: Store the data and index in the table space , All tables are stored in the same data file ,InnoDB The size of the table is limited to the size of the operating system file , It's usually 2GB.
7、 Storage space :
(1)MyISAM: Can be compressed , Less storage space . Three different storage formats are supported : Static table ( Default , But notice that there cannot be spaces at the end of the data , Will be removed )、 Dynamic table 、 Compression meter .
(2)InnoDB: Need more memory and storage , It creates its own buffer pool in main memory for caching data and indexes .
8、 The specific number of rows in the table :
(1)MyISAM: Holds the total number of rows in a table , If select count() from table; I'm just going to pull it out , No need for a full table scan .
(2)InnoDB: The total number of rows in a table is not saved , If you use select count() from table; Need to traverse the entire table , Quite a lot of consumption .
9、 Applicable scenario :
(1) If necessary, provide rollback 、 Crash resilience ACID Business ability , And it is required to realize row lock level concurrency control ,InnoDB Is a good choice ;
(2) If the data table is mainly used to query records , Read operations are far more than write operations and do not need the support of database transactions , be MyISAM The engine can provide high processing efficiency ;
Four 、 Storage engine operations :
1、 see Mysql Storage engine information for :
mysql > show engines;
Query results :
Support The value of the column indicates whether an engine can use :YES Indicates that it can be used 、NO Indicates not available 、DEFAULT Indicates that the engine is the current default storage engine .
2、 Check which engine the database uses by default , Use command :
show variables like ‘storage_engine’;
The query result is :
3、 Set the default storage engine :
(1) stay MySQL In the configuration file (linux for /etc/my.cnf), stay mysqld Add... To the back default-storage-engine=INNODB that will do .
Or add... To the command line when starting the database server –default-storage-engine or –default-table-type Options .
(2) Specify the type of storage engine when creating the table :
CREATE TABLE mytable (id int, title char(20)) ENGINE = INNODB;(3) Modify the storage engine used by existing tables :
ALTER TABLE mytable ENGINE = MyISAM;shortcoming : ① This transformation takes a lot of time and I/O,mysql To perform row by row replication from the old table to the new table , So the efficiency is relatively low ; ② During the conversion, the source table is read locked ; ③ Do table conversion from one engine to another , All special features belonging to the original engine will be lost , For instance from innodb To myisam be innodb Your index will be lost !
(4) Export and then import : If the table is created with MyISAM, Now you want to change the storage engine of the entire database table , Generally, you need to modify one table by one , More complicated , You can export the database first , obtain SQL, hold MyISAM Modified into INNODB, The way of re import .
Related blog :https://blog.csdn.net/gaohuanjie/article/details/50944782
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/100073.html Link to the original text :https://javaforall.cn
边栏推荐
- Analyze apache SH script
- 从检查点恢复后读取不到mysql的数据有那位兄台知道原因吗
- 科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度
- PhpSpreadsheet读写Excel文件
- Static keyword continuation, inheritance, rewrite, polymorphism
- Does rapid software delivery really need to be at the cost of security?
- Number theory - division and blocking
- Laravel 创建自己的 Facade 扩展 geoip 根据 IP 获取国家、地域、城市信息
- 0. grpc environment setup
- wirehark数据分析与取证infiltration.pacapng
猜你喜欢

Cloud native enthusiast weekly: cool collection of grafana monitoring panels

从零实现深度学习框架——LSTM从理论到实战【理论】

5-1系统漏洞扫描
Evolution from stand-alone to distributed database storage system

软件测试方法和技术知识点有哪些?

啃下大骨头——排序(一)

5-1 system vulnerability scanning

#第三天
![The server quickly sets up the alist integrated network disk website [pagoda panel one click deployment of alist]](/img/96/3e634c173c96082881286ba402a067.png)
The server quickly sets up the alist integrated network disk website [pagoda panel one click deployment of alist]

在线文本数字识别列表求和工具
随机推荐
Why does copying files on a shared folder on a local area network (ERP server) result in the loss of the local Internet
Online text digit recognition list summation tool
Processing of error b6267342 reported by AIX small machine in production environment
What are the software testing methods and technical knowledge points?
IFLYTEK AI learning machine summer new product launch AI + education depth combination to create a new height of products
Qt5.14.2 error connecting to the MySQL database of Ubuntu 20.04
laravel 关联模型 多态关系
云原生爱好者周刊:炫酷的 Grafana 监控面板集合
低代码、端到端,一小时构建IoT示例场景,声网发布灵隼物联网云平台
如果我在珠海,到哪里开户比较好?究竟网上开户是否安全么?
Nacos-配置中心基本使用
Underlying principles of file operations (file descriptors and buffers)
Static keyword continuation, inheritance, rewrite, polymorphism
js函数相关的复习
Does rapid software delivery really need to be at the cost of security?
啃下大骨头——排序(一)
Realizing deep learning framework from zero -- LSTM from theory to practice [theory]
Ansible automatic operation and maintenance
STM32 basic knowledge points
The soft youth under the blessing of devcloud makes education "smart" in the cloud