Fixing "Lock wait timeout exceeded; try restarting transaction" for a "Stuck" MySQL Table
A MySQL table can become "stuck" due to various reasons, such as long-running queries or uncommitted transactions. One common error message associated with this is "Lock wait timeout exceeded; try restarting transaction."
This issue can occur when a query is executed without a proper WHERE clause, resulting in repeated updates to the same column for all rows in the table. Additionally, frequent index updates can compound the problem.
To resolve this issue and unfreeze the table, it is necessary to identify and terminate the stuck transactions. The following steps can be taken:
Use the SHOW PROCESSLIST; command to list all running threads in the MySQL command line interface or phpMyAdmin. Identify any threads with significantly high execution times.
For threads with excessive execution times, use the KILL command followed by the corresponding thread ID. This will terminate the connection for that thread. In phpMyAdmin, there is a convenient "Kill" button that can be used for this purpose.
To kill thread 115 from the command line, enter the following:
KILL 115;
This will terminate the stuck transaction and unlock the table, allowing normal operations to resume.
The above is the detailed content of How to Fix \'Lock wait timeout exceeded; try restarting transaction\' for a \'Stuck\' MySQL Table?. For more information, please follow other related articles on the PHP Chinese website!