会话1:
mysql> select * from test_main;
+----+---------+
| id | value |
+----+---------+
| 1 | ONE |
| 2 | TWO |
| 3 | THREE-3 |
| 4 | FOUR-4 |
| 6 | SIX |
+----+---------+
5 rows in set (0.00 sec)
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
mysql> UPDATE test_main SET value = 'FOUR-4' WHERE id = 4;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
会话2:
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
mysql> UPDATE test_main SET value ='THREE-3' WHERE id = 3;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
会话1:
UPDATE test_main SET value ='THREE-5' WHERE id = 3;
因为会话2 已经锁定了 id=3 的这行数据,
因此, 当前会话暂时不能更新被锁定行, 进入锁定等待状态......
然后, 另外开个 会话3, 执行前面的查询语句......