假设我们有2笔交易。
交易1:
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where id = 200 for update; // sql1
Empty set (0.00 sec)
然后开始交易2:
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where id = 200 for update; // sql2
Empty set (0.00 sec)
mysql> update user set name='' where id = 200; // sql3
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> insert into user values(200,''); // sql4
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
两个事务的隔离级别均为REPEATABLE-READ