当前位置:网站首页>[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
边栏推荐
- 杰理之如若需要大包发送,需要手机端修改 MTU【篇】
- Jerry needs to modify the profile definition of GATT [chapter]
- Chrome view page FPS
- UWA pipeline version 2.2.1 update instructions
- 树莓派3B更新vim
- 学go之路(一)go的基本介绍到第一个helloworld
- Crawling exercise: Notice of crawling Henan Agricultural University
- Go learning -- implementing generics based on reflection and empty interfaces
- leetcode59. 螺旋矩阵 II(中等)
- Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
猜你喜欢
杰理之BLE【篇】
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
Cookie技术&Session技术&ServletContext对象
【mysql学习笔记30】锁(非教程)
Detailed explanation | detailed explanation of internal mechanism of industrial robot
树莓派串口登录与SSH登录方法
Markdown 中设置图片图注
首发织梦百度推送插件全自动收录优化seo收录模块
Set picture annotation in markdown
作者已死?AI正用艺术征服人类
随机推荐
Setting and using richview trvstyle template style
升级版手机检测微信工具小程序源码-支持多种流量主模式
MVVM of WPF
数据仓库建设思维导图
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
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
变量的命名规则十二条
word设置目录
杰理之BLE【篇】
杰理之BLE【篇】
Idea console color log
Uni app practical project
Detailed explanation | detailed explanation of internal mechanism of industrial robot
【mysql学习笔记30】锁(非教程)
Project GFS data download
Set picture annotation in markdown
Leetcode59. spiral matrix II (medium)
Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
Internal and external troubles of "boring ape" bayc
学go之路(一)go的基本介绍到第一个helloworld