当前位置:网站首页>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 存储引擎表的写操作(加写表),会阻塞其他进程对同一表的读和写作操,只有当写表释放后,才会执行其他进程的读写操作
- 简单来说:读锁会阻塞写,而写锁会阻塞读写
边栏推荐
- 如何实现call、apply、bind
- Introduction to Qt (5) - file operation, hotkey and mouse reading (implementation of txt window)
- 如何使用 Eolink 实现 API 文档自动生成
- MySQL indexes a field in a table
- A preliminary study on the use of ndk and JNI
- LeetCode:最长有效括号
- DHCP's defense mechanism - DHCP Snooping (DHCP snooping)
- [PP-YOLOv2] Test a custom dataset
- 【Verilog基础】关于芯片中信号串扰的理解
- (2022牛客多校四)K-NIO‘s Sword(思维)
猜你喜欢
线性筛求积性函数
Kubernetes 资源核心原理
(2022牛客多校五)B-Watches(二分)
postman request+加密解密
Kubernetes与OpenStack
(2022杭电多校五)1010-Bragging Dice (思维)
2022杭电多校五 C - Slipper (dijkstra+虚拟结点)
JS中的原型与原型链
sess.restore() 和 tf.import_meta_graph() 在使用时的一些关联
微信小程序错误 undefined Expecting ‘STRING‘,‘NUMBER‘,‘NULL‘,‘TRUE‘,‘FALSE‘,‘{‘,‘[‘, got ]解决方案
随机推荐
[PP-YOLOv2] Test a custom dataset
wps表格怎么调整表格大小?wps表格调整表格大小的方法
【LaTex异常与错误】 - 公式编号的参考引用命令\eqref发生错误Undefined control sequence——可能是因为没加载宏包amsmath
Use Mongoose populate to implement multi-table associative storage and query, with complete code included
JSDay1-合并两个有序数组
Small program figure display banner
WeChat applet develops some function usage methods
Taro小程序跨端开发入门实战
word文档标题怎么自动编号?
(2022牛客多校四)K-NIO‘s Sword(思维)
Qt入门(四)——连续播放图片(两种定时器的运用)
Excuse me: is it safe to pay treasure to buy fund on
微信小程序错误 undefined Expecting ‘STRING‘,‘NUMBER‘,‘NULL‘,‘TRUE‘,‘FALSE‘,‘{‘,‘[‘, got ]解决方案
(2022牛客多校五)G-KFC Crazy Thursday(二分+哈希/Manacher)
有了国产 DevOps 工具 ,还怕数字化转型成本高?
Binary tree level traversal and examples
MySQL indexes a field in a table
Kubernetes 企业如何落地
(2022牛客多校三)A-Ancestor(LCA)
Virtual router redundancy protocol VRRP - double-machine hot backup