Every MySQL triage starts with SHOW PROCESSLIST. The columns make sense at a glance — except for State, which is a glossary of MySQL internals. “Waiting for table metadata lock” means one thing; “Sending data” means something else; “Updating” sounds like progress but often isn’t. Picking the right next move (KILL, wait, escalate) requires reading the State column correctly. On a busy cPanel host with 200 active connections, the wrong interpretation extends an incident.
What’s happening
SHOW PROCESSLIST (or SELECT * FROM information_schema.PROCESSLIST for the full SQL in Info) lists every active connection. State values you actually see in practice:
Sleep— connection is idle, waiting for the client to send its next query. Counts towardmax_connectionsandmax_user_connectionsbut uses minimal CPU. A high count of Sleep is usually persistent connections from PHP-FPM. Not a problem.Sending data— actively executing a query and streaming results. Most “long running” queries spend most of their time here. Misleading name: it includes time spent reading from disk, not just sending bytes back.Updating— applying changes to a table. INSERT, UPDATE, DELETE all show this.Sorting result— performing a sort (ORDER BY). If this lasts more than a few seconds on a small table, the sort buffer is too small or the query needs an index.Locked/Waiting for table metadata lock— blocked waiting for another connection to release a lock. The blocker is somewhere else in the list.Waiting for table flush— blocked because FLUSH TABLES or a backup is running and holding a table.Copying to tmp table/Copying to tmp table on disk— the query is materializing intermediate results. On disk version means the in-memory temp table exceededtmp_table_sizeand spilled. Usually means the query needs rewriting.Creating sort index— building a temporary index for sorting. Often a sign of a missing real index.Killed— a KILL was issued but the connection hasn’t finished cleanup yet. Usually clears within seconds; if it persists, the cleanup is stuck (rare).
The Time column is “seconds in the current state.” A query in Sleep for 3000 seconds is fine; a query in Sending data for 3000 seconds is the suspect.
How to verify
mysql -e "SHOW FULL PROCESSLIST" | head -40
mysql -e "SELECT id, user, db, command, time, state, LEFT(info, 80) FROM information_schema.PROCESSLIST WHERE command != 'Sleep' ORDER BY time DESC LIMIT 20"
mysql -e "SELECT state, COUNT(*) FROM information_schema.PROCESSLIST GROUP BY state ORDER BY 2 DESC"
mysql -e "SELECT * FROM information_schema.INNODB_LOCK_WAITS" # MySQL 5.7
mysql -e "SELECT * FROM performance_schema.data_lock_waits" # MySQL 8.0+
The first three are the broad triage. The lock_waits query identifies the blocker-blocked pairs for any waiting connection.
The fix
- Group by State first.
GROUP BY stateshows what’s dominant. 200 connections in Sleep is fine. 50 connections inWaiting for table metadata lockis a lock storm. - For lock storms, find the blocker. The connection holding the lock is the one whose query started earliest (sort by
time DESCor look atinformation_schema.INNODB_TRX.trx_started). KILL QUERY on the blocker releases the queue. - For
Sending datawith long times, run EXPLAIN on the SQL. Likely a missing index. Don’t KILL routinely — analytics queries legitimately take minutes. Investigate first, KILL only if it’s blocking foreground work. - For
Copying to tmp table on disk, the immediate fix is to KILL and let the application retry. The longer fix is to raisetmp_table_sizeandmax_heap_table_sizeto fit the intermediate result in RAM, or rewrite the query to avoid the temp table. - For high Sleep count without other issues, no action needed. If sleeping connections are pushing
max_user_connectionsfor one account, that account’s PHP-FPM has too many children or persistent connections. PHP-side fix. - For State that doesn’t match the documentation, you’re probably on a version with a new state name. MariaDB 10.x and MySQL 8.x have added several new states for InnoDB internals. Check the version-specific manual.
- Automate the triage:
Snapshot every 5 seconds during an incident. Patterns are easier to see in a sequence.while true; do date mysql -e "SELECT state, COUNT(*) FROM information_schema.PROCESSLIST GROUP BY state ORDER BY 2 DESC LIMIT 10" sleep 5 done
For environments where MySQL diagnostic literacy varies across the team, Stack Harbor’s environment management team builds a runbook that maps each common State to a triage decision and ships dashboards that surface lock waits before they become incidents.