当前位置:网站首页>MySQL 高级知识【 MyISAM 读锁写锁限制】
MySQL 高级知识【 MyISAM 读锁写锁限制】
2022-08-08 23:20:00 【张康佳】
MyISAM 自动加锁机制
在执行查询语句(SELECT)前,会自动给涉及的所有表加读锁,在执行增删改操作前,会自动给涉及的表加写锁。
二、MySql 的表级锁的两种模式
1.表共享读锁(Table Read Lock)
当前session | 其他 session | |
---|---|---|
读锁表 | √ | √ |
写锁表 | × | 阻塞更新 |
读未锁表 | × | √ |
写未锁表 | × | √ |
2.表独占写锁(Table Write Lock)
当前session | 其他 session | |
---|---|---|
读锁表 | √ | 阻塞查询 |
写锁表 | √ | 阻塞更新 |
读未锁表 | × | √ |
写未锁表 | × | √ |
注意
1.有时效写锁测试没有效果是因为 mysql 存在查询缓存。
2.当手动连续执行两次锁表操作时,最后执行的语句生效。
例如:
LOCK TABLE test01 READ;
LOCK TABLE test02 READ;
(test02 表生效)
总结
- 对 MyISAM 存储引擎表的读操作(加读锁),不会阻塞其他进程对同一表的读请求,但会阻塞同一表的写请求,只有当读锁释放后,才会执行其他进行的写操作。
- 对 MyISAM 存储引擎表的写操作(加写表),会阻塞其他进程对同一表的读和写作操,只有当写表释放后,才会执行其他进程的读写操作
- 简单来说:读锁会阻塞写,而写锁会阻塞读写
边栏推荐
- wps表格下拉选项怎么添加?wps表格下拉选项的添加方法
- DHCP's defense mechanism - DHCP Snooping (DHCP snooping)
- JS中数组扁平化的几种方法
- (2022牛客多校四)N-Particle Arts(思维)
- 第二课:概率论
- C语言中指针的介绍
- MPLS Virtual Private Network Everywhere in Life
- Qt入门(五)——文件操作、热键和鼠标的读取(txt窗口的实现)
- [Tensorflow2] Some interface changes of tensorflow1.x-tensorflow2.x
- (2022杭电多校三)1009.Package Delivery(贪心)
猜你喜欢
(2022牛客多校三)A-Ancestor(LCA)
CTF Attack and Defense World
Application Layer Protocol - RADIUS
(2022杭电多校五)1010-Bragging Dice (思维)
(2022牛客多校五)B-Watches(二分)
2022牛客多校六 A-Array(构造+哈夫曼)
Dynamic Host Configuration Protocol DHCP (DHCPv4)
2021 RoboCom 世界机器人开发者大赛-本科组(决赛)7-1绿色围栏(模拟)
Introduction to Qt (5) - file operation, hotkey and mouse reading (implementation of txt window)
2022杭电多校五 C - Slipper (dijkstra+虚拟结点)
随机推荐
WeChat applet error undefined Expecting 'STRING','NUMBER','NULL','TRUE','FALSE','{','[', got ]Solution
(2022牛客多校四)H-Wall Builder II(思维)
如何使用 Eolink 实现 API 文档自动生成
C language library function summary2019.10.31
(Codeforce 757)E. Bash Plays with Functions(积性函数)
考证必看 | PMP扫盲贴+PMP材料
数组去重的几种方法
CTF Attack and Defense World
(2022牛客多校五)D-Birds in the tree(树形DP)
JS中的原型与原型链
Learning experience of bp neural network
(2022牛客多校五)B-Watches(二分)
如何实现call、apply、bind
Introduction to Qt (4) - Continuous playback of pictures (the use of two timers)
stm32 uses serial port to receive idle interrupt + dma to achieve variable length dma reception
MySQL给表里的某个字段建立索引
【LaTex异常与错误】 - 公式编号的参考引用命令\eqref发生错误Undefined control sequence——可能是因为没加载宏包amsmath
(2022牛客多校四)A-Task Computing (排序+动态规划)
2021 RoboCom 世界机器人开发者大赛-本科组(决赛)7-4猛犸不上 Ban(最短路)
Excuse me: is it safe to pay treasure to buy fund on