- Check which processes are currently running and locking the table:
SHOW PROCESSLIST;
- Identify long-running transactions that might be causing the lock:
SELECT * FROM information
schema.innodb
trx ORDER BY trx_started;
- Kill any specific process that is unnecessarily holding the lock and is safe to terminate. Replace `process_id` with the actual ID of the process you intend to kill:
KILL process_id;
- Check for any open table locks:
SHOW OPEN TABLES WHERE In_use > 0;
- If the issue persists, consider restarting the MySQL service to clear all locks (ensure this is acceptable in your environment as it will briefly disrupt database access):
sudo systemctl restart mysql