Bobby's Blog

Killing MySQL Queries Which Have Been Sleeping for a Long Period of Time

How to Kill All MySQL Sleeping Processes

In most cases the sleeping MySQL connections should not really be bothering you, however in some cases the very large number of sleeping connections could exhaust all of the available server resources (RAM and CPU) and also you could also hit your max user connections.

You can use this as a temporary solution while you investigate the core issue on why your MySQL connections are not being closed and get your website patched!

Here’s a cool short script that you could use to kill those long sleeping MySQL queries that are exhausting the resourcing on your server:

You can get it from github if you prefer:

https://github.com/bobbyiliev/kill-sleeping-mysql-processes

Just download the script and execute it!

You can also run it as a cron job, the cron would look something like this:

Hope that this helps 🙂


About the author

Bobby

Linux System Administrator