I have many servers that have applications that do not close connections properly or that use a connection pool. Sometimes I get a lot of sleeping connections that I want to kill. So here is a simple bash script you can use to kill the sleeping connections.
#!/bin/bash
user=<user name>
pass=<password>
for i in /tmp/*.sock ;
do
for j in $(mysql -u$user -p$pass -S $i -e 'show processlist' | grep 'sleep' | awk '{print $1}' )
do
mysql -u$user -p$pass -S $i -e "kill $j"
done
done

Posted in
Tags: 
