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

后端 未结 23 1904
温柔的废话
温柔的废话 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:24

    You need to kill them one by one, MySQL does not have any massive kill command. You can script it in any language, for example in PHP you can use something like:

    $result = mysql_query("SHOW FULL PROCESSLIST");
    while ($row=mysql_fetch_array($result)) {
      $process_id=$row["Id"];
      if ($row["Time"] > 200 ) {
        $sql="KILL $process_id";
        mysql_query($sql);
      }
    }
    

提交回复
热议问题