MySQL事件自动kill运行时间超时的SQL

delimiter $
create event my_long_running_trx_monitor
on schedule every 1 minute
starts '2015-09-15 11:00:00'
on completion preserve enable do
begin
declare v_sql varchar(500);
declare no_more_long_running_trx integer default 0;
declare c_tid cursor for
select concat ('kill ',trx_mysql_thread_id,';')
from information_schema.innodb_trx
where timestampdiff(minute,trx_started,now()) >= 1;
declare continue handler for not found
set no_more_long_running_trx=1;

open c_tid;
repeat
fetch c_tid into v_sql;
set @v_sql=v_sql;
prepare stmt from @v_sql;
execute stmt;
deallocate prepare stmt;
until no_more_long_running_trx end repeat;
close c_tid;
end;
$
delimiter ;

posted on 2016-10-16 21:13  erisen  阅读(1154)  评论(0编辑  收藏  举报

导航