Home  >  Article  >  Database  >  What does mysql deadlock mean?

What does mysql deadlock mean?

王林
王林Original
2020-06-24 15:28:503716browse

Mysql deadlock refers to two or more transactions occupying each other on the same resource and requesting to lock the resources occupied by each other, resulting in a vicious cycle. The InnoDB storage engine can detect deadlock circular dependencies and return an error immediately. A deadlock can only be broken by partially or completely rolling back one of the transactions.

What does mysql deadlock mean?

What is a deadlock? How did it come about?

Deadlock refers to two or more transactions occupying each other on the same resource and requesting to lock the resources occupied by each other, resulting in a vicious cycle.

(Recommended tutorial: mysql tutorial)

When a transaction attempts to lock resources in a different order, a deadlock may occur. Deadlock may also occur when multiple transactions lock the same resource at the same time.

The behavior and order of locks are related to the storage engine. Executing statements in the same order, some storage engines will deadlock and some will not - the cause of deadlock is twofold: a real data conflict; and the way the storage engine is implemented.

Detecting Deadlock

The database system implements various deadlock detection and deadlock timeout mechanisms. The InnoDB storage engine can detect deadlock circular dependencies and return an error immediately.

Deadlock recovery

After a deadlock occurs, the deadlock can be broken only by partially or completely rolling back one of the transactions.

The current way InnoDB handles deadlocks is to roll back the transaction holding the least row-level exclusive lock. Therefore, transactional applications must consider how to deal with deadlocks when designing them. In most cases, only the transactions that were rolled back due to deadlocks need to be re-executed.

The above is the detailed content of What does mysql deadlock mean?. 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