Is it possible mysql to auto kill queries which took more than let`s say 2开发者_C百科0 seconds ?
I guess you are looking for maatkit utility called mk-kill that will kill queries that match certain criteria.
It's possible to write a program which does it. Your program would use SHOW PROCESSLIST
to discover the currently running queries and how long they've been running, then issue a KILL
query to terminate one.
Install the RubyGem mysql_manager
(sudo gem install mysql_manager
) and then add a command like this to your crontab:
mysql-manager --kill --kill:user api --kill:max-query-time 30 --log:level DEBUG
For more options, run mysql-manager --help
.
You might need to specify an alternative --db:dsn
, --db:username
, or --db:password
.
Read more about it here: https://github.com/osterman/mysql_manager
精彩评论