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

后端 未结 23 1939
温柔的废话
温柔的废话 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 ";
        exit;
    fi;
    
    DB=${1};
    for i in `mysql -u  -h localhost ${DB} -p -e "show processlist" | sed 's/\(^[0-9]*\).*/\1/'`; do
        echo "Killing query ${i}";
        mysql -u  -h localhost ${DB} -p -e "kill query ${i}";
    done;
    

提交回复
热议问题