mysql 清理command為sleep的連接進程


  批量刪除 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)”,執行成功。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM