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

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

    Mass killing operation saves time. Do it in MySql itself:

    Run these commands

    mysql> select concat('KILL ',id,';') from information_schema.processlist
    where user='root' and time > 200 into outfile '/tmp/a.txt';
    
    mysql> source /tmp/a.txt;
    

    Reference

    ---------edit------------
    

    if you do not want to store in file, store in a variable

    Just run in your command prompt

    > out1=$(mysql -B test -uroot -proot --disable-column-names  -e "select concat('KILL ',id,';') from information_schema.processlist where user='root' and time > 200;")
    
    > out2= $(mysql -B test -uroot -proot --disable-column-names  -e "$out1")
    

提交回复
热议问题