Home >Database >Mysql Tutorial >批量杀死 MySQL 连接

批量杀死 MySQL 连接

WBOY
WBOYOriginal
2016-06-07 15:08:141043browse

下面简述 2 种方法 ㈠ 巧用 information_schema.processlist mysql select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/killall.txt';mysql source /tmp/killall.txt; ㈡ 在 Bash 层用 AWK 实现 ①

     下面简述 2 种方法
     

     ㈠ 巧用 information_schema.processlist


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

mysql> source /tmp/killall.txt;


     ㈡ 在 Bash 层用 AWK 实现
     
     ① 杀掉所有


mysqladmin -uroot -p processlist|awk -F "|" '{print $2}'|xargs -n 1 mysqladmin -uroot -p kill


     ② 杀掉指定、比如:Rocky


mysqladmin -uroot -p processlist|awk -F "|" '{if($3 == "Rocky")print $2}'|xargs -n 1 mysqladmin -uroot -p kill 


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn