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
原文地址:https://www.cnblogs.com/audiclouddba/p/7363349.html