当前位置:网站首页>MySQL global lock and table lock
MySQL global lock and table lock
2022-07-05 23:55:00 【ADU】
MYSQL The lock inside can be divided into : Global lock , Table lock , Row-level locks
1 Global lock
Lock the whole database instance
MYSQL Provide global lock reading methods :Flush tables with read lock(FTWRL)
This command makes the entire library read-only , After using this command , Data update statement 、 Data definition statements and commit statements of update class transactions are blocked
1.1 Use scenarios
Global logical backup
risk :
- If the main database is backed up , Cannot update during backup , Business suspension
- If backing up from the Library , Cannot perform primary database synchronization during backup binlog, Cause master-slave delay
The official logic backup tool mysqlddump, When mysqldump Using parameter –single-transaction When , Will start a transaction , Make sure you get a consistent view . because MVCC Support for , The data in this process can be updated normally
Consistent reading is good , But only if the engine supports this isolation level
If you want the full library to be read-only , Why not use set global readonly=true The way ???
1 In some systems ,readonly The value of will be used for other logic , For example, judge the primary and standby databases . So modify global The way variables affect too much
2 There are differences in exception handling mechanisms , If you execute FTWRL After the command, due to the abnormal disconnection of the client , that MYSQL This global lock will be released automatically , The whole library can return to the normal update state . Instead, set the entire library to readonly after , If the client has an exception , Then the database will remain readonly state , This will cause the entire library to be in a non writable state for a long time , High risk
2 Table lock
MYSQL There are two kinds of meter level locks inside , One is watch lock , One is metadata lock (meta data lock, MDL)
2.1 Table locks
Syntax of table lock : lock tables…read/write
have access to unlock tables Active release lock , It can also be released automatically when the client is disconnected .lock tables The syntax will restrict the reading and writing of other threads , It also defines the next operation objects of this thread
about InnoDB This kind of engine supports row lock , commonly Don't use lock tables Command to control concurrency , After all, locking the whole table still has a great impact .
2.2 MDL
You don't need to explicitly use , It will be added automatically when accessing a table
effect : Ensure the correctness of reading and writing
1 When adding, deleting, modifying and querying a table , Add MDL Read the lock
2 When changing the table structure , Add MDL Write lock
3 Read locks are not mutually exclusive
4 Read-write lock , Write locks are mutually exclusive , It is used to ensure the security of the schema operation of the change table
5 MDL Will not be released until the transaction is committed , When making table structure changes , Be careful not to lock online queries and updates
边栏推荐
- 数据库遇到的问题
- 零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
- Fiddler Everywhere 3.2.1 Crack
- Spire.PDF for NET 8.7.2
- Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
- 哪些偏门项目可以做到?自媒体做到月赚一万以上很难吗?
- Redis high availability - master-slave replication, sentinel mode, cluster
- PV static creation and dynamic creation
- 【在线聊天】原来微信小程序也能回复Facebook主页消息!
- 传输层协议------UDP协议
猜你喜欢
激光slam学习记录
20. Migrate freetype font library
SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
单商户V4.4,初心未变,实力依旧!
如何让同步/刷新的图标(el-icon-refresh)旋转起来
QT QPushButton details
GFS distributed file system
跟着CTF-wiki学pwn——ret2libc1
数据库遇到的问题
随机推荐
Single merchant v4.4 has the same original intention and strength!
云呐|固定资产管理系统主要操作流程有哪些
el-cascader的使用以及报错解决
Spire Office 7.5.4 for NET
Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
21. PWM application programming
Qcombox (rewrite) + qcompleter (auto completion, auto loading the drop-down options of qcombox, setting the background color)
STM32__ 06 - single channel ADC
The difference of time zone and the time library of go language
时区的区别及go语言的time库
China Jinmao online electronic signature, accelerating the digitization of real estate business
如何让同步/刷新的图标(el-icon-refresh)旋转起来
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
GFS分布式文件系統
云呐|固定资产管理系统功能包括哪些?
保研笔记一 软件工程与计算卷二(1-7章)
Bao Yan notebook IV software engineering and calculation volume II (Chapter 8-12)
CloudCompare&PCL 点云随机添加噪声