Metadata Locks on a Schema
An RDBMS will use metadata locking to help it ensure data consistency and to control which concurrent process has access to database objects.
Sometimes an application will have business-reasons to handle its own row-level locking. Metadata locking, on the other hand, applies at the level of the whole table, not the individual row. It can also apply to other database objects, such as the whole schema, or a stored procedure or trigger.
MySQL
In MySQL use the performance_schema and the metadata_locks table to learn about active locks. For example, all locks for a specific DB schema can be listed with:
SELECT * FROM metadata_locks
WHERE OBJECT_SCHEMA = 'MySchemaHere'
ORDER BY OBJECT_NAME;
MySQL also provides functions that can be used is managing metadata locks. Functions such as:
GET_LOCK()
IS_FREE_LOCK()
RELEASE_LOCK()
RELEASE_ALL_LOCKS()
Full documentation here.
These "memory tickler" posts are quick-hits to refresh my mind about little technical details that arise infrequently enough that I forget in between, and wind up doing an internet search every time. By posting them here, they will be easier to find as needed.)