MySQL 事务锁 in share mode

MySQL In share mode 事务锁是比较常用的共享锁

select ... from lock in share mode;   生成表级共享锁,允许其它线程读取数据但不能修改数据。

--First thread
mysql> select * from test lock in share mode;
+------+------+
| id   | name |
+------+------+
|    1 | fee  |
+------+------+
1 row in set (0.00 sec)

--Second thread
mysql> update test where id = 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id = 1' at line 1
mysql> update test set id = 2  where id = 1;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

 

posted @ 2017-08-15 09:25  Kevin_audia8  阅读(1006)  评论(0编辑  收藏  举报