Analysis and processing method of MySQL deadlock problem

Source: Internet
Author: User

The MyISAM and memory storage engines use a table-level lock Table-level locking

Dead lock
the so-called deadlock <deadlock>: refers to two or more than two processes in the process of execution,
A phenomenon of waiting for resources that cannot be pushed forward without external forces.
At this point, the system is called a deadlock state or the system produces a deadlock, and these aulympic processes are called deadlock processes forever.

A table-level lock does not produce a deadlock. So the main solution to the deadlock is really the most commonly used InnoDB.

When you encounter a problem


First perform show processlist to find the deadlock thread number. Then kill Processno.

Of course, the main solution or need to look at the specific operation. A deadlock may occur
Show InnoDB status check engine state to see which statements produce deadlocks

Show Processlist View the state of the table in the database and whether it is locked;

Kill ID//destroy the locked table

===================================================

The code is as follows Copy Code

Set autocommit=0;

SELECT * from t1 where uid= ' xxxx ' for update//row lock with index (for example, UID) or table lock

INSERT into T1 values (1, ' xxxxx ');

Commit

=====================================================

Lock tables T1 write|read;

INSERT into T1 values (2, ' xxxxx '); Insert only

Unlock tables;

Solutions

1. Full table Scan, no index available.
2, solve the SQL in your program, put in into a join,
3, in the MySQL My.ini the database connection time to change the small point.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.