0
我試圖創建函數,將殺死所有沉睡的連接:MySQL函數殺死熟睡的連接
CREATE DEFINER=`user`@`%` FUNCTION `kill_sleepers`() RETURNS int(11)
BEGIN
DECLARE Id, result INT;
DECLARE done INT DEFAULT FALSE;
DECLARE sleepers CURSOR FOR SELECT Id FROM INFORMATION_SCHEMA.processlist where COMMAND = 'Sleep';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
SET result = 0;
OPEN sleepers;
read_loop: LOOP
FETCH sleepers INTO Id;
IF done THEN
LEAVE read_loop;
END IF;
kill Id;
SET result = result + 1;
END LOOP;
CLOSE sleepers;
RETURN result;
END
但是當我運行它,我得到了「錯誤代碼:1094未知線程ID:0」。如果我把殺入:
IF Id != 0 THEN
kill Id;
SET result = result + 1;
END IF;
它會殺了什麼,我犯了什麼錯誤?