且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将共享升级到互斥锁时避免MySQL死锁

更新时间:2023-02-22 21:33:28

这是一个长期存在的错误,您可以从以下地方阅读更多信息:

This is a long standing bug which you can read more from: This bug report

这是MySQL级表锁定中的问题.

This is a problem in MySQL-level table locking.

在InnoDB内部,FOREIGN KEY约束检查可能会读取(或, 带有ON UPDATE或ON DELETE子句,写入)父表或子表.

Internally inside InnoDB, a FOREIGN KEY constraint check may read (or, with ON UPDATE or ON DELETE clause, write) parent or child tables.

通常,表访问受以下锁控制: 1. MySQL元数据锁定 2. InnoDB表锁 3. InnoDB记录锁

Normally, table access is governed by the following locks: 1. MySQL meta-data lock 2. InnoDB table lock 3. InnoDB record locks

所有这些锁将保留到事务结束.

All these locks are held until the end of the transaction.

在某些模式下会跳过InnoDB表和记录锁,但是 不在外键检查期间.死锁是因为MySQL 仅为显式获取的表获取元数据锁 在SQL语句中提到.

The InnoDB table and record locks are skipped in certain modes, but not during foreign key checks. The deadlock is caused because MySQL acquires the meta-data lock only for the table(s) that are explicitly mentioned in the SQL statements.

我想一种解决方法是访问孩子(或父母) 交易开始时的表格,有问题的外汇之前 按键操作.

I guess that a workaround could be to access the child (or parent) tables at the start of the transaction, before the problematic FOREIGN KEY operation.

阅读讨论内容和回复内容

Read the discussion and it's reply's