为什么mysql默认情况下很难出现死锁?

因为mysql的死锁检查机制innodb_deadlock_detect,默认是打开的

 

CREATE TABLE `exception` (
  `id` int(11) NOT NULL,
  `c` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;
insert into exception(id, c) values(1,1),(2,2),(3,3),(4,4);

 

在第一个客户端执行如下sql

 

客户端1 客户端2
begin; begin;
update exception set c=100 where id=1;  
  update exception set c=300 where id=2;
update exception set c=200 where id=2;  
  update exception set c=400 where id=1;
   
   

 

mysql死锁检查机制,会让死锁根本无法发生:

 

 

posted on 2021-05-16 22:07  坚守梦想  阅读(73)  评论(0编辑  收藏  举报