The following answer was written by Eric Leschinki in 2014/15 at https://stackoverflow.com/a/26743484/1709587 (now deleted):
Mini walkthrough on how to detect locked tables:
This may prevent the database from enforcing atomicity in the affected tables and rows. The locks were designed to make sure things stay consistent and this procedure will prevent that process from taking place as designed.
Create your table, insert some rows
create table penguins(spam int, ham int); insert into penguins(spam, ham) values (3, 4);
show open tables:
show open tables like "penguins"
prints:
your_database penguins 0 0
Penguins isn't locked, lets lock it:
LOCK TABLES penguins READ;
Check if it's locked:
show open tables like "penguins"
Prints:
your_database, penguins 1, 0
Aha! It is locked! Lets unlock it:
unlock tables
Now it is unlocked:
show open tables like "penguins"
Prints:
your_database penguins 0 0
show all current locks
show open tables where in_use <> 0
It would be much more helpful if the MySQL developers put this information in a regular table (so I can do a
select my_items from my_table where my_clauses
), rather than this stripped down 'show table' syntax from system variables.