Tuesday, January 27, 2015

MySQL: Kill sleeping connections using script

Kill Sleep Queries

It’s all too common for me to come across a box that is hopelessly overloaded with Apache requests and MySQL queries. Sometimes, it takes some brute force to keep the whole box from going under. When all else fails, I use the following one-liner to kill off all of those queries that have been running for too long.

mysql> select concat('KILL ',id,';') from information_schema.processlist where Command =    'Sleep'   and Time > 60 into outfile '/tmp/sleep_processes.txt'"
mysql> source /tmp/sleep_processes.txt

1 comment:

sadas said...

very nice post i am interested your post
website designing company in india

Optimizing the Linux (OS) for Database

Optimizing the Linux (OS) for Database Optimizing the operating system (OS) for a Database Server/MySQL server involves configuring various ...