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

后端 未结 23 1896
温柔的废话
温柔的废话 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:35
    #! /bin/bash
    if [ $# != "1" ];then
        echo "Not enough arguments.";
        echo "Usage: killQueryByDB.sh <db_name>";
        exit;
    fi;
    
    DB=${1};
    for i in `mysql -u <user> -h localhost ${DB} -p<password> -e "show processlist" | sed 's/\(^[0-9]*\).*/\1/'`; do
        echo "Killing query ${i}";
        mysql -u <user> -h localhost ${DB} -p<password> -e "kill query ${i}";
    done;
    
    0 讨论(0)
  • 2020-12-04 05:36

    We can do it by MySQL Workbench. Just execute this:

    kill id;
    

    Example:

    kill 13412
    

    That will remove it.

    0 讨论(0)
  • 2020-12-04 05:36

    I used the command flush tables to kill all inactive connections which where actually the mass problem.

    0 讨论(0)
  • 2020-12-04 05:39

    Query 1 select concat('KILL ',id,';') from information_schema.processlist where user='username' into outfile '/tmp/a.txt';

    Query 2 source a.txt

    This will enable you to kill all the queries in show processlist by specific user.

    0 讨论(0)
  • 2020-12-04 05:40
    mysqladmin pr -u 'USERNAME' -p'PASSWORD' | awk '$2~/^[0-9]+/{print $2}' | xargs -i mysqladmin -u 'USERNAME' -p'PASSWORD' kill {}
    
    0 讨论(0)
提交回复
热议问题