批量刪除 sleep 進程狀態的連接數解決方法。
直接在MySQL命令控制台操作:
mysql> show processlist; mysql> SELECT concat('KILL ',id,';') FROM information_schema.processlist WHERE user='user1'; mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt'; mysql> source /tmp/a.txt;
其中上面root用戶是“show processlist;” 命令下,User列對應最多的Sleep進程連接狀態的用戶。
注:如上面導出為指定文件路徑報“ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement”錯誤。
是由於MySQL在文件的導入、導出有個默認的文件路徑。通過“show variables like '%secure%';”命令查看默認導入、導出文件路徑。
從上面可看出默認路徑為“/var/lib/mysql-files/”;所以改下導出文件路徑:
mysql> SELECT concat('KILL ',id,';') FROM information_schema.processlist WHERE user='root' into outfile '/var/lib/mysql-files/a.txt';
然后在執行“source /var/lib/mysql-files/a.txt;”命令,接下來是出現一堆“Query OK, 0 rows affected (0.00 sec)”,執行成功。