|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
浙公网安备 33010602011771号