当前位置:网站首页>[MySQL learning notes 30] lock (non tutorial)
[MySQL learning notes 30] lock (non tutorial)
2022-07-06 07:19:00 【yqs_ two hundred and eighty-one million eight hundred and seven】
classification
- Global lock : Lock a library
- Table lock : Lock a watch
- Row-level locks : Lock a line of records
Global lock
Global lock is to lock the entire database , After locking, the entire database will be in a read-only state , Other operations will block .
The application scenario is that a global lock needs to be added when backing up a consistent database , Prevent data changes during backup .
Use global locks
flush tables with read lock;
mysql Backup command
mysqldump -u root -p 1234 db_name>backup.sql
Table lock
classification
- Table locks ( It is divided into read lock and write lock)
- Metadata lock (meta data lock,MDL)
- Intent locks
Metadata lock
brief introduction
Metadata lock has mysql The system controls itself , We don't need to show using . Metadata lock is mainly used to maintain the data consistency of metadata , When there are active transactions on the table , You cannot write metadata .
understand
Metadata can be understood as the structural information of a table , When there are active transactions on a table , Metadata lock will be automatically added , Prevent the table structure from being modified during the operation data, resulting in various unexpected situations .
Lock timing
When adding, deleting, modifying and querying a table , Add MDL Read the lock .
When changing the structure of a table , Add MDL Write lock .
Add watch lock
lock tables Table name read;
Once the read lock is added , All connections, including yourself, cannot be written , Only read
lock tables Table name write;
Once the write lock is added , The locked connection can read and write , Other connections cannot be read or written
Unlock
unlock tables;
Intent locks
Introduce
Through the intentional lock , When another thread adds a table lock, it does not need to traverse all rows to determine whether it can add a lock , Improved efficiency .
classification
Intention sharing lock : By statement select … lock in share mode add to , Compatible with table lock sharing lock , Mutually exclusive with exclusive lock
Intention exclusive lock : from insert、update、delete、select … for update add to , Shared locks with table locks and exclusive locks are mutually exclusive
Row-level locks
Introduce
Row-level locks , Each operation locks the corresponding row of data . Minimum locking force , The probability of lock conflict is the lowest , Highest concurrency . Apply to InnoDB In the storage engine .
InnoDB The data is organized based on indexes , Row locking is achieved by locking the index items on the index , Instead of locking records
classification
- Row lock : Lock a single row record , Prevent other transactions from doing this update and delete.
- Clearance lock : Lock index record gap ( This record is not included ), Ensure that the index record gap remains unchanged , Prevent other transactions from going on in this gap insert, Produce pleasure .
- Temporary key lock : Is a combination of row lock and clearance lock , It is equivalent to the clearance lock of the closed interval
Row lock
- Shared lock : Allow other transactions to read
- Exclusive lock : Prohibit other transactions from reading and writing
ps: If the addition, deletion and modification conditions do not cover the index , that Innodb All records will be locked , Just upgrade to table lock
Clearance lock / Temporary key lock
边栏推荐
- Short video, more and more boring?
- Word delete the contents in brackets
- Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
- 微信公众号无限回调授权系统源码 全网首发
- 学go之路(一)go的基本介绍到第一个helloworld
- 微信脑力比拼答题小程序_支持流量主带最新题库文件
- 【MySQL学习笔记32】mvcc
- Word setting directory
- TS基础篇
- Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
猜你喜欢
随机推荐
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
杰理之BLE【篇】
Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
UWA pipeline version 2.2.1 update instructions
1189. Maximum number of "balloons"
Yield method of tread
leetcode1020. Number of enclaves (medium)
[some special grammars about C]
Uni app third party package configuration network request
微信脑力比拼答题小程序_支持流量主带最新题库文件
The differences and advantages and disadvantages between cookies, seeion and token
剪映的相关介绍
Cookie Technology & session Technology & ServletContext object
Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
Résumé de la structure du modèle synthétisable
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
杰理之BLE【篇】
Word setting directory