Kill All Sleeping MySQL Connections

Sometimes you may find that your server has a ton of MySQL connections with their state set to “Sleep”

mysqladmin proc | grep Sleep | awk '{print $2}' | while read LINE; do mysqladmin kill $LINE; done

This will clear out those connections. You will need to look at your MySQL config and see how long you’re allowing connections to remain open. Furthermore if there is a single user opening too many you need to limit max client connections.

This entry was posted in Bash One-Liners and tagged , , , , , , . Bookmark the permalink.

Leave a Reply