Kill slow mysql queries

Rate this post

A Shell script for killing slow MySQL queries:

#!/bin/sh

# Credentials for a MySQL user with PROCESS, SUPER permissions
USERNAME=
PASSWORD=

# MySQL Server location
HOST=
PORT=3306

TIMEOUT=60 # 1 minute
TARGET_USER= # MySQL user to monitor

MYSQL=”mysql -u $USERNAME –password=$PASSWORD -h $HOST -P $PORT -B”

$MYSQL -N -e ‘SHOW FULL PROCESSLIST’ | cut -f 1,2,6 | awk ‘{ if ($3 > $TIMEOUT && $2 == $TARGET_USER) print “KILL ” $1 “;” }’

Source: https://gist.github.com/paulrosania/2883869

You can set the cron job to do the activity every minutes.

Learn more – How to schedule cron job

Linux Cron Job – Schedule Job in linux: crontab

 

For any query or issue, feel free to discuss on http://discuss.eduguru.in

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

%d bloggers like this: