MySQL死锁日志

查看数据库死锁日志

  查看命令:show engine innodb status \G
  说明:通过show engine innodb status 查看的日志是最新一次记录死锁的日志,但是查看不到完整的事务的sql,通常显示当前正在等待锁的sql;

死锁日志解析

  • lock_mode X locks rec but not gap:模式排它锁,类型行锁;
  • lock_mode X locks gap before rec :模式排它锁,类型gap锁;
  • lock_mode X locks gap before rec insert intention:模式排它锁,类型插入意向锁;
  • lock_mode X:Next-key锁;
2019-04-23 19:30:55 0x7f30bc478700
*** (1) TRANSACTION:
//第一个事务ID
TRANSACTION 6310726, ACTIVE 0 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 4 lock struct(s), heap size 1136, 2 row lock(s)
MySQL thread id 3972328, OS thread handle 139847097263872, query id 68564302 10.83.188.19 test@dd updating

//当前事务正在等待获取锁的SQL
update file
     SET file_name = 'dwm_gulf_passenger_finish_behavior_his',


        file_desc = '改造测试',


        file_type = 100,


        project_id = 743,


        file_folder_id = '4fae643d3a924a5b84aa366c94173bfb',


        last_edit_time = '2019-04-23 19:30:55',


        last_edit_user = 'zhangsan',


        file_lock_user = '',


        current_version = 1,


        file_lock_status = 0,


        file_delete = 0,


        use_type = 1,


        schedule_uuid = 'aa.bb',


        commit_status = 1,


        share = 0,


        creator_user = 'zhangsan',


        create_time = '2019-04-23 17:54:46',

//当前事务正在等待获取锁的信息
*** (1)  WAITING FOR THIS LOCK TO BE GRANTED :
#等待锁信息:类型行锁,在file表的主键索引上,模式排它锁,没有GAP锁
RECORD LOCKS space id 57 page no 779 n bits 80 index PRIMARY of table `test`.`file` trx id 6310726 lock_mode X locks rec but not gap waiting(只是等待行锁,不包含gap锁)
//等待记录锁的具体信息,共22个字段
Record lock, heap no 5 PHYSICAL RECORD: n_fields 22; compact format; info bits 0
 0: len 8; hex 8000000000001726; asc        &;;
 1: len 6; hex 000000604b45; asc    `KE;;
 2: len 7; hex 27000000a112b6; asc '      ;;
 3: len 30; hex 64776d5f67756c665f70617373656e6765725f66696e6973685f62656861; asc dwm_gulf_passenger_finish_beha; (total 38 bytes);
 4: len 30; hex e4b893e8bda6e794a8e688b7e5ae8ce68890e8a18ce4b8bae8a1a82de69a; asc                            -  ; (total 52 bytes);
 5: len 4; hex 80000064; asc    d;;
 6: len 8; hex 00000000000002e7; asc         ;;
 7: len 30; hex 346661653634336433613932346135623834616133363663393431373362; asc 4fae643d3a924a5b84aa366c94173b; (total 32 bytes);
 8: len 5; hex 99a2ef37b7; asc    7 ;;
 9: len 10; hex 66756775616e71695f69; asc fuguanqi_i;;
 10: len 0; hex ; asc ;;
 11: len 8; hex 8000000000000001; asc         ;;
 12: len 4; hex 80000000; asc     ;;
 13: len 4; hex 80000000; asc     ;;
 14: len 4; hex 80000001; asc     ;;
 15: len 30; hex 626173655f64772e64776d5f67756c665f70617373656e6765725f66696e; asc base_dw.dwm_gulf_passenger_fin; (total 46 bytes);
 16: len 4; hex 80000001; asc     ;;
 17: len 30; hex 23212f62696e2f626173680a2323205348454c4c0a232323232323232323; asc #!/bin/bash ## SHELL #########; (total 4979 bytes);
 18: len 4; hex 80000000; asc     ;;
 19: len 10; hex 66756775616e71695f69; asc fuguanqi_i;;
 20: len 4; hex 5cbee0e6; asc \   ;;
 21: len 12; hex 53484544554c455f5441534b; asc SHEDULE_TASK;;

*** (2) TRANSACTION:
//事务2信息
TRANSACTION 6310725, ACTIVE 0 sec inserting, thread declared inside InnoDB 5000
mysql tables in use 1, locked 1
5 lock struct(s), heap size 1136, 3 row lock(s), undo log entries 2
MySQL thread id 3962755, OS thread handle 139847293961984, query id 68564303 10.83.189.16 test@dd update
//当前事务等待锁的SQL
insert into file_version
     ( file_id,


        file_version,


        commit_time,


        commit_user,


        schedule_uuid,


        file_type,


        use_type,


        file_desc,


        file_name,


        status,


        change_type,


        is_current_prod,


        project_id,


        file_content,


        comment,


        schedule_content,


        file_property_content )
     values ( 5926,


        1,


        '2019-04-23 19:30:55',


        'zhangsan',


        'aa.bb',


        100,


        1,


        '测试'

//当前事务持有的锁信息
*** (2) HOLDS THE LOCK(S):
#持有锁信息:行锁,在file表的主键索引上,没有GAP锁
RECORD LOCKS space id 57 page no 779 n bits 80 index PRIMARY of table `datastudio`.`file` trx id 6310725 lock_mode X locks rec but not gap(行锁)
//当前事务持有的行锁信息,当前记录22个字段
Record lock, heap no 5 PHYSICAL RECORD: n_fields 22; compact format; info bits 0
 0: len 8; hex 8000000000001726; asc        &;;
 1: len 6; hex 000000604b45; asc    `KE;;
 2: len 7; hex 27000000a112b6; asc '      ;;
 3: len 30; hex 64776d5f67756c665f70617373656e6765725f66696e6973685f62656861; asc dwm_gulf_passenger_finish_beha; (total 38 bytes);
 4: len 30; hex e4b893e8bda6e794a8e688b7e5ae8ce68890e8a18ce4b8bae8a1a82de69a; asc                            -  ; (total 52 bytes);
 5: len 4; hex 80000064; asc    d;;
 6: len 8; hex 00000000000002e7; asc         ;;
 7: len 30; hex 346661653634336433613932346135623834616133363663393431373362; asc 4fae643d3a924a5b84aa366c94173b; (total 32 bytes);
 8: len 5; hex 99a2ef37b7; asc    7 ;;
 9: len 10; hex 66756775616e71695f69; asc fuguanqi_i;;
 10: len 0; hex ; asc ;;
 11: len 8; hex 8000000000000001; asc         ;;
 12: len 4; hex 80000000; asc     ;;
 13: len 4; hex 80000000; asc     ;;
 14: len 4; hex 80000001; asc     ;;
 15: len 30; hex 626173655f64772e64776d5f67756c665f70617373656e6765725f66696e; asc base_dw.dwm_gulf_passenger_fin; (total 46 bytes);
 16: len 4; hex 80000001; asc     ;;
 17: len 30; hex 23212f62696e2f626173680a2323205348454c4c0a232323232323232323; asc #!/bin/bash ## SHELL #########; (total 4979 bytes);
 18: len 4; hex 80000000; asc     ;;
 19: len 10; hex 66756775616e71695f69; asc fuguanqi_i;;
 20: len 4; hex 5cbee0e6; asc \   ;;
 21: len 12; hex 53484544554c455f5441534b; asc SHEDULE_TASK;;

//当前事务等待锁的信息
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
#等待锁信息:行锁,在file_version表的idx_fid_fversion索引上,没有GAP锁
RECORD LOCKS space id 59 page no 377 n bits 608 index idx_fid_fversion of table `test`.`file_version` trx id 6310725 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 533 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: len 8; hex 0000000000001728; asc        (;;
 1: len 8; hex 8000000000000001; asc         ;;
 2: len 8; hex 0000000000002f64; asc       /d;;

//日志含义:数据库最终选择回滚事务1
//说明:当数据库检测到死锁后,会按照某种策略计算出每个事务的代价,回滚代价最小的事务从而解开死锁
*** WE ROLL BACK TRANSACTION (1)

参考:

  1. https://825635381.iteye.com/blog/2339503
  2. http://www.fanyilun.me/2017/04/20/MySQL加锁分析/

你可能感兴趣的:(Mysql)