Created
June 6, 2012 18:51
-
-
Save tessro/2883869 to your computer and use it in GitHub Desktop.
A script for killing slow MySQL queries, suited for a cron job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Credentials for a MySQL user with PROCESS, SUPER permissions | |
USERNAME= | |
PASSWORD= | |
# MySQL Server location | |
HOST=127.0.0.1 | |
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 ";" }' |
@birendra14 $1 $2 and $3 are refering to the values from the cut statement beforehand - so $3 is process time, $2 is user and $1 is process id.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
can you tell me which value have been assign to $1,$2,$3?