MySQL 8.0 Reference Manual Including MySQL NDB Cluster 8.0

26.12.12.3 The metadata_locks Table

MySQL uses metadata locking to manage concurrent access to database objects and to ensure data consistency; see Section 8.11.4, “Metadata Locking”. Metadata locking applies not just to tables, but also to schemas, stored programs (procedures, functions, triggers, scheduled events), tablespaces, user locks acquired with the GET_LOCK() function (see Section 12.14, “Locking Functions”), and locks acquired with the locking service described in Section 29.3.1, “The Locking Service”.

The Performance Schema exposes metadata lock information through the metadata_locks table:

This information enables you to understand metadata lock dependencies between sessions. You can see not only which lock a session is waiting for, but which session currently holds that lock.

The metadata_locks table is read only and cannot be updated. It is autosized by default; to configure the table size, set the performance_schema_max_metadata_locks system variable at server startup.

Metadata lock instrumentation uses the wait/lock/metadata/sql/mdl instrument, which is enabled by default.

To control metadata lock instrumentation state at server startup, use lines like these in your my.cnf file:

To control metadata lock instrumentation state at runtime, update the setup_instruments table:

The Performance Schema maintains metadata_locks table content as follows, using the LOCK_STATUS column to indicate the status of each lock:

The metadata_locks table has these columns:

The metadata_locks table has these indexes:

TRUNCATE TABLE is not permitted for the metadata_locks table.