MySQL Connections
07 March 2012

We've been having connection issues with our MySQL servers at work. Today I see a lot of connections that have been open for 1000+ seconds. Here's a quick way to find them:

mysqladmin processlist | grep [databasename] | awk '{if($12>1000) print $2, $6, $12}'
You want to grep for the database name so you don't inadvertently get and kill system processes. You could also put the condition in the awk where clause for more accuracy.

Then you can take that list and kill the mysql process ids

mysqladmin kill [id1],[id2],[id3]....
If you're really adventurous, you could pipe the ID's straight to mysqladmin kill, but that's a little dangerous.