首页 > 解决方案 > MySQL 在同一条记录上死锁

问题描述

我不时收到 MySQL 死锁错误。似乎一个事务正在持有并等待同一个记录锁。这怎么可能发生?

------------------------
LATEST DETECTED DEADLOCK
------------------------
2021-03-28 02:05:00 2b89b1836700
*** (1) TRANSACTION:
TRANSACTION 22774383040, ACTIVE 0 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 376, 1 row lock(s)
MySQL thread id 4862793, OS thread handle 0x2b83dfb8a700, query id 18125913470  manhattanowner statistics
select * from tb_ride where id=3857302 for update
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 224 page no 70133 n bits 98 index `PRIMARY` of table `Manhattan`.`tb_ride` trx id 22774383040 lock_mode X locks rec but not gap waiting
Record lock, heap no 98 PHYSICAL RECORD: n_fields 26; compact format; info bits 0


*** (2) TRANSACTION:
TRANSACTION 22774382499, ACTIVE 1 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 376, 2 row lock(s)
MySQL thread id 4862794, OS thread handle 0x2b89b0e77700, query id 18125912089 
select * from tb_ride where id=3857302 for update
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 224 page no 70133 n bits 98 index `PRIMARY` of table `Manhattan`.`tb_ride` trx id 22774382499 lock_mode X locks rec but not gap
Record lock, heap no 98 PHYSICAL RECORD: n_fields 26; compact format; info bits 0
 

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 224 page no 70133 n bits 98 index `PRIMARY` of table `Manhattan`.`tb_ride` trx id 22774382499 lock_mode X locks rec but not gap waiting
Record lock, heap no 98 PHYSICAL RECORD: n_fields 26; compact format; info bits 0

标签: mysqlmultithreading

解决方案


推荐阅读