Home > Database > Mysql Tutorial > body text

How to avoid mysql deadlock

青灯夜游
Release: 2020-09-18 09:13:07
Original
8306 people have browsed it

Methods to avoid mysql deadlock: 1. Access tables and rows in a fixed order; 2. Large transactions are more prone to deadlock. If the business allows, split large transactions into smaller ones; 3. In the same transaction , try to lock all the resources required at once to reduce the probability of deadlock; 4. Reduce the isolation level; 5. Add reasonable indexes to the table.

How to avoid mysql deadlock

How to avoid deadlocks as much as possible:

1. Access tables and rows in a fixed order. For example, for two transactions that update data, transaction A updates data in the order 1, 2; transaction B updates data in the order 2, 1. This is more likely to cause deadlock.

2. Break down big things into small pieces. Large transactions are more prone to deadlock. If the business allows, split the large transactions into smaller ones.

3. In the same transaction, try to lock all the resources required at once to reduce the probability of deadlock.

4. Lower the isolation level. If the business permits, it is also a good choice to lower the isolation level. For example, adjusting the isolation level from RR to RC can avoid many deadlocks caused by gap locks.

5. Add reasonable indexes to the table. It can be seen that if the index is not used, a lock will be added to each row of the table, and the probability of deadlock will be greatly increased.

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!