How do I kill all the processes in Mysql “show processlist”?

后端 未结 23 1948
温柔的废话
温柔的废话 2020-12-04 04:49

Because I see a lot of processes there, and the \"time\" column shows big values for all of them.

23条回答
  •  囚心锁ツ
    2020-12-04 05:16

    I recently needed to do this and I came up with this

    -- GROUP_CONCAT turns all the rows into 1
    -- @q:= stores all the kill commands to a variable
    select @q:=GROUP_CONCAT(CONCAT('KILL ',ID) SEPARATOR ';')  
    FROM information_schema.processlist 
    -- If you don't need it, you can remove the WHERE command altogether
    WHERE user = 'user';
    -- Creates statement and execute it
    PREPARE stmt FROM @q;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    

    That way, you don't need to store to file and run all queries with a single command.

提交回复
热议问题