Detecting locked tables (locked by LOCK TABLE)

Marcin picture Marcin · Mar 23, 2010 · Viewed 204.9k times · Source

Is there a way to detect locked tables in MySQL? I mean tables locked by the LOCK TABLE table WRITE/READ command.

(Note that readers interested in detecting named locks acquired with GET_LOCK should read Show all current locks from get_lock instead.)

Answer

Aruman picture Aruman · Aug 25, 2012

Use SHOW OPEN TABLES: http://dev.mysql.com/doc/refman/5.1/en/show-open-tables.html

You can do something like this

SHOW OPEN TABLES WHERE `Table` LIKE '%[TABLE_NAME]%' AND `Database` LIKE '[DBNAME]' AND In_use > 0;

to check any locked tables in a database.