Alex Rivera | Logout

How can I stop a MySQL query if it takes too long?

Asked 2010-01-26T01:52:45.500
47

Is it possible to timeout a query in MySQL?

That is, if any query exceeds the time I specify, it will be killed by MySQL and it will return an error instead of waiting for eternity.

Edit
Report

1 Answer

3

Here is my script :

mysql -e 'show processlist\G' |\
egrep -b5 'Time: [6-9]{3,10}' |\
grep 'Id:' |\
cut -d':' -f2 |\
grep -v '155' |\ ## Binary Log PID
sed 's/^ //' |\
while read id
do
    mysql -e "kill $id;"
done
answered 2011-11-29T11:11:59.897

Your Answer