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.