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

SHOW ENGINE INNODB STATUS

  The SHOW ENGINE INNODB STATUS command in MySQL provides detailed information about the internal state of the InnoDB storage engine. This ...