MySQL 1152: Table cannot be locked.

  1. Check which processes are currently running and locking the table:


SHOW PROCESSLIST;

  1. Identify long-running transactions that might be causing the lock:


SELECT * FROM informationschema.innodbtrx ORDER BY trx_started;

  1. 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;

  1. Check for any open table locks:


SHOW OPEN TABLES WHERE In_use > 0;

  1. 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

Master

MySQL

in Minutes — Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the whitepaper on your email!
Oops! Something went wrong while submitting the form.

MySQL

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the whitepaper on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid