|NO.Z.00157|——————————|BigDataEnd|——|Java&MySQL.高级.V29|——|MySQL.v30|表级锁|写锁演示|

一、表级锁之写锁演示
### --- 加写锁测试
~~~     在窗口1中 对mylock01表加写

lock table mylock01 write;
~~~     在窗口1中, 对 mylock01 进行读写操作, 都是可以进行的

select * from mylock01 where id = 1;
update mylock01 set title = 'a123' where id = 1;
mysql> select * from mylock01 where id = 1;
+----+-------+
| id | title |
+----+-------+
|  1 | a1    |
+----+-------+
1 row in set (0.00 sec)
mysql> update mylock01 set title = 'a123' where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
### --- 在窗口1中读其他表, 还是不允许
~~~     在窗口2 中读mylock01 表, 读操作被阻塞
~~~     在窗口2 中 对mylock01表进行写操作, 仍然被阻塞
~~~     释放锁, 窗口2操作执行执行.

select * from mylock01;
update mylock01 set title = 'a456' where id = 1;
unlock tables;
二、总结: 
### --- 总结: 

~~~     对MyISAM表加写锁, 会阻塞其他进程对同一表的读和写操作,
~~~     只有当写锁释放后,才会执行其他进程的操作

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(6)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示