shell指令结束mysql指定用户的所有进程

作者:袖梨 2022-11-14

例子,在linux中操作

QQ图片20150812190828

$2横向第二栏用户栏

代码如下 复制代码
for i in $(mysql -uroot -p123456 -se "show processlist" |
awk '{if($2=="admin")print $1}');do mysql -uroot -p123456 -e "kill $i";done

例子,在mysql中解决

代码如下 复制代码

mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root';
+------------------------+
| concat('KILL ',id,';') |
+------------------------+
| KILL 3101; |
| KILL 2946; |
+------------------------+
2 rows in set (0.00 sec)

mysql>select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt';
Query OK, 2 rows affected (0.00 sec)

mysql>source /tmp/a.txt;
Query OK, 0 rows affected (0.00 sec)

相关文章

精彩推荐