* 通过创建存储过程来执行
CREATE PROCEDURE `kill_long_transaction`()
COMMENT '终止长时间运行的事务'
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()) >= 60;
declare continue handler for not found
BEGIN
SET no_more_long_running_trx=1;
SELECT 1 INTO @handler_invoked FROM (SELECT 1) AS t;
END;
open c_tid;
repeat
fetch c_tid into v_sql;
IF NOT no_more_long_running_trx THEN
set @v_sql=v_sql;
IF @v_sql IS NOT NULL THEN
prepare stmt from @v_sql;
execute stmt;
deallocate prepare stmt;
END IF;
END IF;
until no_more_long_running_trx end repeat;
close c_tid;
END;