What Does Thread Status "Waiting for table metadata lock" in the MySQL Server Processlist Mean? (Doc ID 1365549.1)

Last updated on FEBRUARY 02, 2017

Applies to:

MySQL Server - Version 5.5 and later
Information in this document applies to any platform.

Goal

Since version 5.5 there is a new thread state in the output of SHOW PROCESSLIST:

Waiting for table metadata lock


Sometimes a query hangs in this state for a long time without obvious reason:

mysql> show processlist\G
*************************** 1. row ***************************
     Id: 6589
   User: root
   Host: localhost
     db: mysql
Command: Sleep
   Time: 401
  State:
   Info: NULL
*************************** 2. row ***************************
     Id: 6590
   User: root
   Host: localhost
     db: mysql
Command: Query
   Time: 395
  State: Waiting for table metadata lock

   Info: optimize table user
*************************** 3. row ***************************
     Id: 6591
   User: root
   Host: localhost
     db: NULL
Command: Query
   Time: 0
  State: NULL
   Info: show processlist
3 rows in set (0.00 sec)

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms