当前位置:网站首页>Mysql database - storage engine
Mysql database - storage engine
2022-06-21 21:12:00 【[email protected]】
List of articles
1 MySQL Storage engine
1.1 Introduction to the concept of storage engine
MySQL The data in is stored in files with various technologies , Each technology uses a different storage mechanism 、 Indexing techniques 、 Lock levels and ultimately provide different functions and capabilities , These different technologies and supporting functions are in MySQL It's called storage engine in
The storage engine is MySQL Storage mode or storage format of data stored in file system
1.2 MySQL Common storage engines
MySQL Components in the database , Responsible for executing the actual data I/O operation
MySQL In the system , The storage engine is on top of the file system , The data is transferred to the storage engine before it is saved to the data file , Then, it is stored according to the storage format of each storage engine
1、MyISAM
2、InnoDB
1.2.1 MyISAM
1、MyISAM Characteristics
MyISAM Unsupported transaction , Foreign key constraints are not supported either , Full text indexing only , Data files and index files are kept separately
Fast access , There is no requirement for transaction integrity
MyISAM Suitable for inquiry 、 Insertion based applications
MyISAM Store three files on disk , The file name and table name are the same , But the extensions are :
.frm Definition of file storage table structure
The extension of the data file is .MYD (MYData)
The extension of the index file is .MYI (MYIndex)
Table level locking form , Lock the entire table when the data is updated
Databases block each other in the process of reading and writing :
It will block the reading of user data in the process of data writing
It will also block the user's data writing in the process of data reading
Data is written or read separately , The process is fast and takes up less resources
2、MyISAM Table support 3 Different storage formats :
(1) static state ( Fixed length ) surface
Static tables are the default storage format . Fields in static tables are immutable , So every record is a fixed length , The advantage of this storage method is that the 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 table
Dynamic tables contain variable fields , Records are not fixed length , The advantage of this storage is that it takes up less space , But frequent updates 、 Deleting records will cause fragmentation , It needs to be carried out on a regular basis OPTIMIZE TABLE Sentence or myisamchk -r Command to improve performance , And it's relatively difficult to recover in case of failure .
(3) Compression meter
The compressed table consists of myisamchk Tool creation , Take up a very small space , Because each record is compressed individually , So there's only a very small cost of access .
3、MyISAM Applicable production scenarios
Business doesn't need the support of business
Read or write data unilaterally
MyISAM The storage engine reads and writes data frequently, which is not suitable for the scenario
Using read-write concurrency to access relatively low business
Business with relatively little data modification
Services that do not require very high consistency of data services
The server hardware resources are relatively poor
1.2.2 InnoDB
1、InnoDB characteristic
Support transactions , Support 4 Transaction isolation levels
MySQL from 5.5.5 Version start , The default storage engine is InnoDB
Read and write blocking is related to transaction isolation level
It can cache index and data very efficiently
Tables and primary keys are stored in clusters
Support partition 、 Table space , similar oracle database
Support for foreign key constraints ,5.5 Full text indexing is not supported before ,5.5 Full text index is supported after
The requirement for hardware resources is relatively high
Row level locking , But all Table scanning will still be table level locking , Such as
update table set a=1 where user like ‘%lic%’;
InnoDB The number of rows in the table is not saved , Such as select count() from table; when ,InnoDB You need to scan the entire table to calculate how many rows there are , however MyISAM Simply read out the number of saved lines . It should be noted that , When count() The statement contains where When the conditions MyISAM You also need to scan the entire table
For self growing fields ,InnoDB Must contain only the index of this field , But in MyISAM You can create a composite index with other fields in the table
When you empty the entire table ,InnoDB It's line by line deletion , Efficiency is very slow .MyISAM The table is rebuilt
2 View storage engine
2.1 Check out the storage engines supported by the system
show engines;
2.2 Look at the storage engine that the table uses
Method 1
show table status from Library name where name=' Table name '\G;
example :show table status from SCHOOL where name='CLASS'\G;
Method 2
use Library name ;
show create table Table name ;
example :use SCHOOL;
show create table CLASS;
3 Modify the storage engine
Method 1 : adopt alter table modify
use Library name ;
alter table Table name engine=MyISAM;
example :use SCHOOL;
alter table CLASS engine=myisam;
show create table CLASS;
Method 2 : By modifying the /etc/my.cnf The configuration file , Specify the default storage engine and restart the service
quit
vim /etc/my.cnf
[mysqld]
default-storage-engine=INNODB
systemctl restart mysqld.service
# Be careful : This method only changes the configuration file and restarts mysql The newly created table is valid after service , The existing table will not be changed .
systemctl restart mysqld.service
Remember to restart after modification mysql service
# Be careful : This method only changes the configuration file and restarts mysql The newly created table is valid after service , The existing table will not be changed .
Method 3 : adopt create table Specify the storage engine when creating the table
use Library name ;
create table Table name ( Field 1 data type ,...) engine=MyISAM;
example :mysql -u root -p
use SCHOOL;
create table hellolic (name varchar(10),age char(4))engine=myisam;
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211932347124.html
边栏推荐
猜你喜欢

【CTF】攻防世界 MISC

高性能内网DNS系统介绍

【MySQL·水滴计划】第三话- SQL的基本概念

PCA based face recognition system and face pose analysis

Intersection of vector and plane

NS32F103VBT6软硬件替代STM32F103VBT6

Unity 模拟手电筒光源探测器,AI攻击范围检测区域,视锥内检测物体,扇形区域检测,圆形区域检测,圆锥区域检测

【owt】p2p Signaling Server 运行

Take off, annual salary: 400000+

总结了嵌入式开发中几种常见的设备通信协议
随机推荐
Show you how to distinguish several kinds of parallelism
LeeCode435 无重叠区间
【MySQL·水滴计划】第三话- SQL的基本概念
AXI_ Bus_ Matrix_ 4x4 design - logic design
Cluster I -- LVS load balancing cluster NAT mode and LVS load balancing actual deployment
Check information on the Internet after the college entrance examination, and pay attention to prevent websites without SSL certificates
Welcome to the markdown editor
集群一---LVS负载均衡集群NAT模式及LVS负载均衡实战部署
Simulate the input and get the contents of print output
History of the Great Game
[Patents and papers-19]: Notice on electronic information application of Nanjing City, Jiangsu Province in 2022 (medium and advanced)
Shutter input box assembly
MediaCodec的数据类型和使用方式
Leecode435 non overlapping interval
How functions are declared
The second round of layoffs in a large factory is coming, and the routine is full
启牛开通证券账户是真实安全的吗?开户收费吗
Citus 11 for Postgres 完全开源,可从任何节点查询(Citus 官方博客)
Which futures account opening platform is good? What are the safe and regular futures companies?
黄金哪些值得注意的技术:资金管理的重要性