关闭自动提交: autocommit=0; SESSION A: Database changed mysql> select * from ProductQuota; +-----------+-------------+ | productSn | frozenQuota | +-----------+-------------+ | 200 | 100 | +-----------+-------------+ 1 row in set (0.00 sec) mysql> select * from test; +----+------+ | id | name | +----+------+ | 1 | a | +----+------+ 1 row in set (0.00 sec) mysql> update ProductQuota set frozenQuota='200' where productSn=200; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update test set name='b' where id=1; ---hang SESSION B: mysql> update test set name='b' where id=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update ProductQuota set frozenQuota='200' where productSn=200; ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction