当前位置:网站首页>[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?

Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes

JDBC learning notes

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

杰理之BLE【篇】

Path analysis model

leetcode59. 螺旋矩阵 II(中等)

微信脑力比拼答题小程序_支持流量主带最新题库文件

Bugku CTF daily question: do you want seeds? Blackmailed

win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
随机推荐
NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections
Excel的相关操作
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
The psychological process from autojs to ice fox intelligent assistance
Solution to the problem of breakthrough in OWASP juice shop shooting range
Select all the lines with a symbol in word and change them to titles
word设置目录
Applied stochastic process 01: basic concepts of stochastic process
leetcode1020. 飞地的数量(中等)
Simple and understandable high-precision addition in C language
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
Cif10 actual combat (resnet18)
NiO programming introduction
word中把带有某个符号的行全部选中,更改为标题
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
杰理之BLE【篇】
LeetCode Algorithm 2181. Merge nodes between zero
Path analysis model
TS Basics
杰理之BLE【篇】