Hosting Operations
Show Active MySQL Sessions
MySQL is slow or rejecting clients and you need a quick view of active sessions.
Command
mysql -e "show full processlist;"
What changed
Nothing changes. MySQL prints current sessions and queries.
Danger
safe
When to use it
Use when MySQL feels saturated, slow, or overloaded.
When not to use it
Do not use this as the kill step; inspect carefully before terminating sessions.
Undo or recovery
No undo needed because this command is read-only.
Expected output
Rows showing connection ID, user, host, database, command, time, state, and query text.
demo script
Disposable terminal steps
mysqladmin statusmysql -e "show processlist;"mysql -e "show full processlist;"
simulated output
What it looks like
::fixture-ready::
$ mysqladmin status
Uptime: 86400 Threads: 7 Questions: 23890 Slow queries: 3 Opens: 112 Open tables: 64 Queries per second avg: 0.276
::exit-code::0
$ mysql -e "show processlist;"
Id User Host db Command Time State Info
17 app 10.0.0.12 shop Query 91 Sending data select * from orders
18 app 10.0.0.13 shop Sleep 20 NULL
22 report 10.0.0.30 analytics Query 680 Copying to tmp table select customer_id
::exit-code::0
$ mysql -e "show full processlist;"
Id User Host db Command Time State Info
17 app 10.0.0.12 shop Query 91 Sending data select * from orders join order_items
18 app 10.0.0.13 shop Sleep 20 NULL
22 report 10.0.0.30 analytics Query 680 Copying to tmp table select customer_id, sum(total) from orders group by customer_id
::exit-code::0
YouTube Short
List MySQL sessions.
Before restarting MySQL, inspect the process list and see who is connected and what they are doing.
LinkedIn hook
The app was waiting behind busy sessions.
Question: What do you check before restarting a slow MySQL server?
experiments
A/B tests to run
Metric: linkedin_save_rate
A: The app was waiting behind busy sessions.
B: Check MySQL processlist before restart.