美文网首页
mysql游标删除相关进程避免锁表

mysql游标删除相关进程避免锁表

作者: Eric_Zeng | 来源:发表于2018-09-11 09:50 被阅读14次

新建函数

BEGIN

declare Done int default 0;

declare id_to_be_killed bigint;

/* 声明游标 */

declare process_ids cursor for

select ID

from information_schema.processlist

where (command = 'sleep' and time > 100) or (info like '%acct_info %');

/* 异常处理 */

declare continue handler for sqlstate '02000' set Done = 1;

/* 打开游标 */

open process_ids;

/*读取值*/

fetch next from process_ids into id_to_be_killed;

repeat

if not Done then

kill id_to_be_killed;

end if;

fetch next from process_ids into id_to_be_killed;

until Done

end repeat;

END

相关文章

网友评论

      本文标题:mysql游标删除相关进程避免锁表

      本文链接:https://www.haomeiwen.com/subject/wypygftx.html