[英]How to limit execution time in MySQL?
I have following code to limit execution time in MySQL but it is not working. 我有以下代码来限制MySQL中的执行时间,但无法正常工作。 Someone help me out.
有人帮我。
delimiter //
CREATE PROCEDURE `classicWatches`.kill_long_running_queries()
BEGIN
DECLARE process_id BIGINT;
DECLARE finished INT DEFAULT 0;
DECLARE kill_process_id CURSOR FOR SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND = 'Query' AND TIME > 5; # only for 5 seconds just testing whether it works or not
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
OPEN kill_process_query;
loop_loop: LOOP
FETCH kill_process_id INTO process_id;
IF process_id >=1 THEN
KILL QUERY process_id ; # Here showing error in mysql workbench but don't know what error
END IF ;
IF finished THEN
LEAVE loop_loop;
END IF;
END LOOP loop_loop;
CLOSE kill_process_id;
END //
delimiter ;
CREATE EVENT kill_long_running_queries
ON SCHEDULE EVERY 10 SECOND
DO CALL `classicWatches`.kill_long_running_queries();
I'm not quite sure what you want to accomplish. 我不太确定您要完成什么。
The error shown in Workbench is because an integer is expected (as shown on line 23 - line 23 is just an example), but it is found
process_id
variable, however, the stored procedure is created and executed correctly when invoked. Workbench中显示的错误是因为需要整数(如第23行所示-第23行只是示例),但是找到了
process_id
变量,但是,存储过程在调用时被正确创建并执行。
The cursor is
kill_process_id
, but on line 13 you open the cursor kill_process_query
does not exist, you need to change for line 14. 游标是
kill_process_id
,但是在第13行上打开的游标kill_process_query
不存在,您需要更改第14行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.