ITPub博客

首页 > 数据库 > MySQL > MySQL死锁案例三(事务提交导致死锁)

MySQL死锁案例三(事务提交导致死锁)

原创 MySQL 作者:StevenBeijing 时间:2020-08-21 18:36:48 0 删除 编辑

测试环境: MySQL 5.7.26

创建测试表: 

mysql> create table t3(id int not null default '0',primary key(id));
Query OK, 0 rows affected (0.00 sec)

插入测试数据:

mysql> insert into t3 values(1);
Query OK, 1 row affected (0.00 sec)

死锁模拟过程如下:

会话1commit之后,会话2核会话3产生死锁,会话3回滚,并抛出:

ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

过程说明:

死锁日志:

LATEST DETECTED DEADLOCK
------------------------
2020-08-21 18:23:54 0x7f39023e7700
*** (1) TRANSACTION:
TRANSACTION 26174234, ACTIVE 8 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1136, 2 row lock(s)
MySQL thread id 208, OS thread handle 139883056465664, query id 3858292 localhost root update
insert into t3 values(1)
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 833 page no 3 n bits 72 index PRIMARY of table `test`.`t3` trx id 26174234 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000018f6307; asc     c ;;
 2: len 7; hex 3b000021e40110; asc ;  !   ;;
*** (2) TRANSACTION:
TRANSACTION 26174241, ACTIVE 5 sec inserting, thread declared inside InnoDB 1
mysql tables in use 1, locked 1
3 lock struct(s), heap size 1136, 2 row lock(s)
MySQL thread id 210, OS thread handle 139882827511552, query id 3858305 localhost root update
insert into t3 values(1)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 833 page no 3 n bits 72 index PRIMARY of table `test`.`t3` trx id 26174241 lock mode S locks rec but not gap
Record lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000018f6307; asc     c ;;
 2: len 7; hex 3b000021e40110; asc ;  !   ;;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 833 page no 3 n bits 72 index PRIMARY of table `test`.`t3` trx id 26174241 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000018f6307; asc     c ;;
 2: len 7; hex 3b000021e40110; asc ;  !   ;;
*** WE ROLL BACK TRANSACTION (2)






来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30135314/viewspace-2713780/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-02-10

  • 博文量
    244
  • 访问量
    325276