Remove image metadata fast — MetaRemover.com

MySQL “waiting for table metadata lock” (2025): diagnose, unblock, prevent

Understand MySQL Metadata Locks (MDL), quickly find blockers, release waits safely, and keep them from returning with better DDL practices, short transactions, and online schema changes.

performance_schemasys schemaonline DDL2025

Typical cause

Long transactions

Risk levelHigh

Resolution speed

Minutes, if known

With a runbookFast

Prevention

Process & DDL

EffectivenessExcellent

What is a metadata lock (MDL)?

MySQL protects table definitions with Metadata Locks (MDL). Readers typically take shared MDL; DDL needs stronger locks. If a long transaction holds a shared MDL, an ALTER/DROP/RENAME may block with “waiting for table metadata lock”.

Note
MDL waits are different from InnoDB row-lock waits. Reducing transaction length and avoiding long-running reads is the #1 fix.

Symptoms & common causes

Symptoms

What you’ll see

  • ALTER TABLE stuck in “waiting for table metadata lock”
  • High concurrency + rising Threads_running
  • Slow or stalled deploys/migrations

Common causes

Why it happens

  • Long transactions holding shared MDL (open transactions, idle in transaction)
  • Long SELECTs (reporting, unbounded scans)
  • Explicit locks: LOCK TABLES, ongoing DDL
Creating incident docs with screenshots? If they include images, remove hidden EXIF/GPS first with MetaRemover.com — browser-only and private.

Diagnose (queries & views)

Find waiters & blockers

schema_table_lock_waits

SELECT * FROM sys.schema_table_lock_waits ORDER BY waiting_query_secs DESC;

Shows waiting/locking thread IDs, queries, and table names.

Unblock safely — runbook

1) Identify blocker

Confirm owner & impact

SELECT * FROM sys.schema_table_lock_waits ORDER BY waiting_query_secs DESC;

Capture blocking thread_id and SQL; notify owner if possible.

2) End minimal work

Prefer KILL QUERY

-- Safer: stop only the current statement
KILL QUERY <thread_id>;

-- Last resort: drop the whole connection (rolls back tx)
KILL <thread_id>;
Caution
Killing a connection aborts the transaction and can cascade to dependent workloads.

If the blocker is your DDL

  • Cancel the DDL (KILL QUERY), re-run during a change window.
  • Prefer online/instant ALTERs in MySQL 8 (ALGORITHM=INPLACE / ALGORITHM=INSTANT when supported).
  • Use online tools like gh-ost or pt-online-schema-change for busy tables.

Prevent future waits

Short transactions

Design & coding

  • Autocommit for read-only sessions
  • Avoid “idle in transaction” (close cursors, commit promptly)
  • Split long reports into batches or replicas

Safer schema changes

Operational practices

  • Schedule DDL windows; announce freezes
  • Use ALGORITHM=INSTANT/INPLACE where possible (MySQL 8)
  • Apply gh-ost / pt-online-schema-change for heavy tables
Preparing a postmortem with screenshots? Clean hidden image metadata (EXIF/GPS) via MetaRemover.com before sharing externally.

FAQ


Stabilize schema changes — prevent MDL incidents

Keep transactions short, schedule DDL windows, and use online schema tools. When sharing incident docs, scrub image metadata first.