Tag: linux

  • 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.