Unlocking a "Stuck" MySQL Table: Troubleshooting "Lock Wait Timeout Exceeded"
When encountering the "Lock wait timeout exceeded; try restarting transaction" error while working with an InnoDB table in MySQL, it's likely that a transaction has become stuck. Here's how to fix the table and resolve the stuck transaction:
1. Identify the Stuck Transaction:
Run the following command in the MySQL command line interface or through phpMyAdmin:
SHOW PROCESSLIST;
This will display a list of running threads. Look for threads with a long execution time or those that are in a "Sleep" state. The corresponding thread ID will be displayed in the "Id" column.
2. Terminate the Stuck Thread:
Once the stuck thread is identified, terminate it using the following command in the command line interface:
KILL;
Replace
3. Restart the Transaction (Optional):
If the transaction is still active, restart it to release any locks it may be holding. You can do this by running the following command:
START TRANSACTION; COMMIT;
4. Drop the Index (If Applicable):
If you previously tried to drop an index on the affected table and it failed due to the lock, try dropping it again after terminating the stuck thread and restarting the transaction.
ALTER TABLEDROP INDEX ;
By following these steps, you can unlock the stuck table and resolve the "Lock wait timeout exceeded" error. Remember to check the running threads regularly to identify and terminate any potential stuck transactions to prevent similar issues in the future.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3