查看mysql死锁日志

show engine innodb status
  •  

找到信息中LATEST DETECTED DEADLOCK这一行,可以看到mysql的死锁信息详情

------------------------
LATEST DETECTED DEADLOCK
------------------------
2017-08-20 01:57:49 7fa264240700
*** (1) TRANSACTION:
TRANSACTION 309164542, ACTIVE 1 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1184, 2 row lock(s), undo log entries 848
MySQL thread id 177543, OS thread handle 0x7fa26c0a0700, query id 698443941 192.168.96.32 root update
INSERT INTO kmsong.km_tbl_companygrandsong(CompanyID, SongID, SongDate) 
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 321 page no 13948 n bits 240 index `idx_companygrandsong_songid` of table `kmsong`.`km_tbl_companygrandsong` trx id 309164542 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 134 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
 0: len 8; hex 3030303234373631; asc 00024761;;
 1: len 8; hex 0000000000016dc8; asc       m ;;

*** (2) TRANSACTION:
TRANSACTION 309164538, ACTIVE 2 sec fetching rows
mysql tables in use 1, locked 1
9714 lock struct(s), heap size 1275432, 632965 row lock(s), undo log entries 565
MySQL thread id 177544, OS thread handle 0x7fa264240700, query id 698448556 192.168.96.32 root updating
delete from kmsong.km_tbl_companygrandsong where CompanyID=-1 AND SongID='00053458'
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 321 page no 13948 n bits 240 index `idx_companygrandsong_songid` of table `kmsong`.`km_tbl_companygrandsong` trx id 309164538 lock_mode X
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
 0: len 8; hex 73757072656d756d; asc supremum;;
  •  

可以很明显看出来是因为批量写入和删除产生了数据库死锁异常。

Logo

更多推荐