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 ;

上一篇:jeecg下实现自动默认模糊查询


下一篇:SQL Server 积累