Quick MySQL Connection Monitoring for Lazy Admins

Ever needed to quickly check who’s hogging your MySQL server? Here’s a one-liner I keep in my toolbox for when things get sluggish.

bash
mysql -e "select user,count(*) FROM information_schema.processlist group by user order by count(*) desc;"

This gives you a quick snapshot of connections per user. But the real magic happens when you need to watch it in real-time:

bash
while true; do mysql -e "select user,count(*) FROM information_schema.processlist group by user order by count(*) desc;"; sleep 5; done

This will refresh every 5 seconds. Perfect for catching that misbehaving WordPress plugin or runaway script that’s creating too many connections.

I’ve used this countless times when developers swear “it can’t be our code” causing connection issues. Spoiler: it usually is.

Pro tip: Adjust the sleep value based on your needs. I use 5 seconds, but you might want faster/slower updates depending on what you’re troubleshooting.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

To respond on your own website, enter the URL of your response which should contain a link to this post’s permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post’s URL again. (Find out more about Webmentions.)