MySQL 死锁 - zLulus/My_Note GitHub Wiki
MySQL死锁问题定位
摘抄自mysql死锁 DeadLock定位与解决
报错内容
Deadlock found when trying to get lock; try restarting transaction
查看产生死锁的具体语句
show engine innodb status;
然后根据具体执行sql分析
思路可以有以下几种:
1.改互斥锁为共享锁;
2.减小上锁范围,避开会产生两个sql语句交集结果的索引,强制使用其他索引查询;
3.思路同2,删除2中提到的上锁范围较大的索引;
Mysql死锁引起的事务未回滚问题
摘抄自Mysql死锁引起的事务未回滚问题 Deadlock found when trying to get lock; try restarting transaction
现象:MySQL执行sql异常,仅回滚了事务超时的最后一条语句
对于InnoDB
数据库引擎,在MySQL 5.6
和5.7
中innodb_rollback_on_timeout
默认值为OFF
,即仅回滚事务超时的最后一条语句。将innodb_rollback_on_timeout
设置为ON
,事务超时后将导致InnoDB中止并回滚整个事务。
修改方式:sql语句(重启后无效);修改my.ini 文件
官方资料
InnoDB rolls back only the last statement on a transaction timeout by default. If --innodb-rollback-on-timeout is specified, a transaction timeout causes InnoDB to abort and roll back the entire transaction.
For more information, see 14.22.4 InnoDB Error Handling.