MySQL死锁问题
不理解为啥出现死锁?
新建表
CREATE TABLE `t2` (
`id` int NOT NULL AUTO_INCREMENT,
`a` int DEFAULT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `a` (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB;
初始化数据
insert into t2(a,b)values(30,30),(60,60);
事务1 | 事务2 | 事务3 | |
---|---|---|---|
t1 | begin; insert into t2(a,b)values(90,90) on duplicate key update b = b + 1; |
||
t2 | insert into t2(a,b)values(90,90) on duplicate key update b = b + 1;(阻塞) | ||
t3 | insert into t2(a,b)values(90,90) on duplicate key update b = b + 1;(阻塞) | ||
t4 | rollback; | ||
t5 | Query OK, 1 row affected | ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction |
本作品采用《CC 协议》,转载必须注明作者和本文链接