Home  >  Article  >  Database  >  How to solve mysql deadlock?

How to solve mysql deadlock?

青灯夜游
青灯夜游Original
2019-05-22 18:36:2412217browse

Mysql deadlock solution: 1. Wait until timeout (innodb_lock_wait_timeout=50s), automatically roll back the transaction; 2. Initiate deadlock detection, actively roll back a transaction, and let other transactions continue to execute ( innodb_deadlock_detect=on).

How to solve mysql deadlock?

MySQL has two deadlock handling methods:

● Wait until timeout (innodb_lock_wait_timeout=50s), Automatically rollback transactions.

● Initiate deadlock detection, proactively roll back a transaction and allow other transactions to continue executing (innodb_deadlock_detect=on).

Due to performance reasons, deadlock detection is generally used to handle deadlocks.

Deadlock detection

The principle of deadlock detection is to construct a directed graph with transactions as vertices and locks as edges, and determine whether there is a cycle in the directed graph. If there is a cycle, there is a deadlock.

Rollback

After detecting a deadlock, select the transaction with the smallest number of inserted, updated or deleted rows to roll back, based on the trx_weight field in the INFORMATION_SCHEMA.INNODB_TRX table.

The above is the detailed content of How to solve mysql deadlock?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn