我遇到过 2 个事务造成 mysql 死锁的情况。
引发以下错误:Deadlock found when trying to get lock; try restarting transaction
如果我是正确的,这个错误意味着mysql死锁超时已过期,并且mysql尝试做一些事情来消除这个死锁。
我不清楚 try restarting transaction
的含义是什么?事务如何“重启”?
这 2 笔锁定交易会怎样?它们都被取消(回滚)吗?或者只是取消其中之一,以便可以释放锁。
提前致谢
最佳答案
没有死锁超时(尽管有锁超时)。如果检测到死锁,无论花多少时间都无法解决它,因此 MySQL 会立即使用react。
MySQL 将回滚一个或多个事务,直到死锁解决。
来自MySQL docs :
InnoDB tries to pick small transactions to roll back, where the size of a transaction is determined by the number of rows inserted, updated, or deleted.
由您的应用程序进行 SQL 调用来重试事务。
MySQL 在其文档 How to Cope with Deadlocks 中有一些建议.
如果您希望尝试避免死锁并且无法理解死锁的原因,我建议您开始另一个问题,并发布完整的受影响的查询和架构,最好是来自 SHOW ENGINE INNODB 的死锁报告状态
。
关于Mysql死锁: what does 'try restarting transaction' mean and what exactly happens to the locked transactions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25445428/