当前位置:网站首页>[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
边栏推荐
- word怎么只删除英语保留汉语或删除汉语保留英文
- navicat如何导入MySQL脚本
- Simple and understandable high-precision addition in C language
- Raspberry pie 3B update VIM
- word设置目录
- Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
- idea控制台彩色日志
- Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
- TypeScript 接口属性
- Crawling exercise: Notice of crawling Henan Agricultural University
猜你喜欢
Configure raspberry pie access network
leetcode59. 螺旋矩阵 II(中等)
The way to learn go (I) the basic introduction of go to the first HelloWorld
L'auteur est mort? Ai utilise l'art pour conquérir l'humanité
配置树莓派接入网络
leetcode704. Binary search (find an element, simple, different writing)
Setting and using richview trvstyle template style
杰理之BLE【篇】
Idea console color log
ORACLE列转行--某字段按指定分隔符转多行
随机推荐
SEO学习的最好方式:搜索引擎
mysql如何合并数据
Compile, connect -- notes-2
word设置目录
SSM learning
杰理之BLE【篇】
Wechat official account infinite callback authorization system source code, launched in the whole network
word中把帶有某個符號的行全部選中,更改為標題
配置树莓派接入网络
Uni app practical project
Path analysis model
呆错图床系统源码图片CDN加速与破解防盗链功能
Openjudge noi 2.1 1749: Digital Square
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
Configure raspberry pie access network
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
剪映的相关介绍
杰理之BLE【篇】
supervisor 使用文档
navicat如何导入MySQL脚本