当前位置:网站首页>Database - MySQL storage engine (deadlock)
Database - MySQL storage engine (deadlock)
2022-07-06 04:25:00 【Enthusiastic masses】
Catalog
- 1、 Concept
- ( One ) Storage engine concept
- ( Two )MyISAM
- 1、MyISAM Introduction to the characteristics of
- 2、MyIAM Supported storage formats
- (1) static state ( Fixed length ) surface
- (2) Dynamic table
- (3) Compression meter
- 3、MyISAM Examples of applicable production scenarios
- ( 3、 ... and )InnoDB
- 1、InnoDB characteristic
- 2、InnoDB It is suitable for production scenario analysis
- 3、 Enterprises choose storage engine based on
- ( Four ) View and set storage engine commands
- 1、 Check out the storage engines supported by the system
- 2、 Look at the storage engine that the table uses
- (1) Method 1 : Direct view
- (2) Method 2 : Enter the database to view
- 3、 Modify the storage engine
- (1) Method 1 : adopt alter table modify
- (2) Method 2 : By modifying the /etc/my.cnf The configuration file , Specify the default storage engine and restart the service
- (3) Method 3 : adopt create table Specify the storage engine when creating the table
- Add : Deadlock 、innodb And myisam
1、 Concept
( One ) Storage engine concept
- 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
- MySQL Common storage engines
MyISAM
InnoDB - 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
( Two )MyISAM
1、MyISAM Introduction to the characteristics of
- MyISAM Unsupported transaction , Foreign key constraints are not supported either , Full text index support , 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 On disk . Stored in three files on the , The file name and table name are the same , But the extensions are :
1、.frm Definition of file storage table structure
2、 The extension of the data file is .MYD(MYData)
3、 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、MyIAM Supported 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 Examples of 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
( 3、 ... and )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 full table scan will still be table level locking , Such as
updata table set a=1 where user like ‘%zhang%’ - 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 , but MyISAM Simply read the number of lines of the save number , 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、InnoDB It is suitable for production scenario analysis
- Business needs transaction support
- Row level locking has a good adaptability to high concurrency , But you need to make sure that the query is done through the index
- Scenarios where business data is updated frequently
Such as : Forum , Microblogging, etc - High requirements for business data consistency
banking business - The memory of hardware device is large , utilize InnoDB Better cache capacity to improve memory utilization , Reduce disk IO The pressure of the
3、 Enterprises choose storage engine based on
- We need to consider the different core functions and application scenarios provided by each storage engine
- Supported fields and data types
All engines support common data types
But not all engines support other field types , Like binary objects - Lock type : Different storage engines support different levels of locking
Table locking :MyISAM Support
Row lock :InnoDB Support - Index support
Indexing can significantly improve performance when searching and recovering data in a database
Different storage engines provide different indexing techniques
Some storage engines don't support indexing at all - Transaction processing support
Improve reliability during updating and inserting information into tables
The storage engine can be selected according to whether the enterprise business needs to support transactions
( Four ) View and set storage engine commands
1、 Check out the storage engines supported by the system
2、 Look at the storage engine that the table uses
(1) Method 1 : Direct view
(2) Method 2 : Enter the database to view
3、 Modify the storage engine
(1) Method 1 : adopt alter table modify
(2) Method 2 : By modifying the /etc/my.cnf The configuration file , Specify the default storage engine and restart the 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 .
(3) Method 3 : adopt create table Specify the storage engine when creating the table
Add : Deadlock 、innodb And myisam
innodb and myisam The difference between ?
myisam | innodb |
---|---|
Transaction and foreign key are not supported | Support transactions and foreign keys |
Table level locking | Row level locking ( use like Fuzzy matching full table scanning is still table level locking ) |
I won't support it MVCC( Multi version concurrency control , Realized reading - Write , Write - Concurrent execution of reads ) | Support MVCC |
Full text index support | 5.5 Full text indexing is not supported before version ,5.5 Post support |
The hardware requirements are not very high , Low resource consumption | High requirements for hardware , Especially memory , Can improve cache capacity |
1. Table name .frm( File storage table structure ) 2. Table name .MYD (MYData Data files ) 3. Table name .MYI (MYIndex Index file ) | 1.db.opt( Table properties file )2. Table name .frm( Table structure file )3. Table name .ibd( Table data metadata ) |
myisam For example, data archives 、 There are few modifications to data such as commodity warehouse 、 Mainly reading 、 Scenarios that read and insert separately and do not support transactions | innodb For example, microblog 、 More reading and writing in forums 、 Scenarios that require high consistency and support transactions |
myisam Pay more attention to reading | innodb Focus on writing |
myisam Search for 、 Fast access | innodb Slightly slower |
myisam No requirements for integrity ( Unsupported transaction ,ACID characteristic ) | innodb With good integrity ( Support transactions ,ACID characteristic ) |
myisam Low security , Slow recovery in case of accident | innodb High safety , Recover faster in an accident |
myisam Poor capacity and force | innodb It can accommodate high concurrency |
InnoDB The relationship between row lock and index
InnoDB Row locking is achieved by locking index entries , If there is no index ,InnoDB The record will be locked by a hidden cluster index .
1)delete from t1 where id=1;
If id Field is primary key ,InnoDB Clustered index is used for primary key , Will directly lock the whole line of records .
2)delete from t1 where name=‘aaa’ ;
If name Fields are normal indexes , Will lock the two rows of the index first , Then the record corresponding to the primary key will be locked .
3)delete from t1 where age=23;
If age Field has no index , Will use full table scanning to filter , At this time, all records on the form will be locked .
Deadlock
Deadlock : Deadlocks are transactions waiting for each other's resources , Finally formed a loop .
How to avoid deadlock as much as possible ?
1) Access tables and rows in a fixed order .
2) Big business, small business . Big business tends to deadlock , If night permits , Break up big business into small ones .
3) In the same transaction , Try to lock all the resources you need at once , Reduce deadlock probability .
4) Reduce isolation level . If business permits , Lowering the isolation level is also a good choice , Let's take the isolation level from RR Adjusted for RC, A lot can be avoided because gap A deadlock caused by a lock .
5) Add a reasonable index to the table . You can see that if you do not index, you will add locks for each row of the table , The probability of deadlock is greatly increased .
边栏推荐
- R note prophet
- Stable Huawei micro certification, stable Huawei cloud database service practice
- Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
- C. The Third Problem(找规律)
- 电脑钉钉怎么调整声音
- Mixed development of QML and QWidget (preliminary exploration)
- 关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
- How many of the 10 most common examples of istio traffic management do you know?
- Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
猜你喜欢
Easyrecovery靠谱不收费的数据恢复电脑软件
MySql數據庫root賬戶無法遠程登陸解决辦法
图应用详解
Basic use of MySQL (it is recommended to read and recite the content)
VNCTF2022 WriteUp
Lombok principle and the pit of ⽤ @data and @builder at the same time
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
查询mysql数据库中各表记录数大小
Is the mode of education together - on campus + off campus reliable
Solve the compilation problem of "c2001: line breaks in constants"
随机推荐
Figure application details
How does computer nail adjust sound
Mysql数据库慢sql抓取与分析
Solution of storage bar code management system in food industry
Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
Fedora/REHL 安装 semanage
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
cdc 能全量拉去oracle 表嘛
VNCTF2022 WriteUp
hashlimit速率控制
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
拉格朗日插值法
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
Several important classes in unity
Fedora/rehl installation semanage
[Zhao Yuqiang] deploy kubernetes cluster with binary package
One question per day (Mathematics)
1291_Xshell日志中增加时间戳的功能
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022