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

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

    If you are using laravel then this is for you:

    $query = "SHOW FULL PROCESSLIST";
        $results = DB::select(DB::raw($query));
    
        foreach($results as $result){
            if($result->Command == "Sleep"){
                $sql="KILL ". $result->Id;
                DB::select(DB::raw($sql));
            }
        }
    

    Of-course, you should use this use Illuminate\Support\Facades\DB; after your namespace.

提交回复
热议问题