Skip to content

View locks and blocking queries in MySQL

Join current lock waits to server threads to identify which session is blocking another transaction.

For MySQL 8, run:

SELECT rt.PROCESSLIST_ID AS waiting_pid,
bt.PROCESSLIST_ID AS blocking_pid,
rp.INFO AS waiting_query,
bp.INFO AS blocking_query
FROM performance_schema.data_lock_waits w
JOIN performance_schema.threads rt
ON rt.THREAD_ID = w.REQUESTING_THREAD_ID
JOIN performance_schema.threads bt
ON bt.THREAD_ID = w.BLOCKING_THREAD_ID
LEFT JOIN information_schema.PROCESSLIST rp
ON rp.ID = rt.PROCESSLIST_ID
LEFT JOIN information_schema.PROCESSLIST bp
ON bp.ID = bt.PROCESSLIST_ID;

Each result pairs a waiting session with a blocking session. This query covers the server, so a blocker can belong to another database.

An idle session can hold transaction locks even when its query text is empty. An empty result says only that this snapshot found no data lock waits; metadata locks and resolved deadlocks need separate checks.

  1. Open Admin › Locks on the affected connection.
  2. Inspect the table, lock mode, granted status, and session IDs.
  3. Compare the waiting and blocking session IDs with the SQL result.
  4. Ask the transaction owner to review whether to commit or roll back.

The Locks view shows data locks for the current database. Use write and run SQL to run the server-wide query above.

If intervention is necessary, follow cancel or kill a query. Stopping a statement alone can leave its transaction and locks open.

The query needs access to performance_schema.data_lock_waits, performance_schema.threads, and the process list. PROCESS permits visibility of other accounts’ sessions. The Locks view also reads performance_schema.data_locks.

These data lock tables are available in MySQL 8. For a version or permission error, see Admin data troubleshooting.

For a deadlock that has already caused rollback, use error 1213. For other delays, use diagnose performance. Return to the MySQL overview.