-
root@localhost > select concat('KILL ',id,';') from information_schema.processlist where user=’sam' into outfile '/tmp/a.txt
脚本内容如下:
-
+------------------------+
-
| concat('KILL
',id,';') |
-
+------------------------+
-
| KILL 31964612; |
-
| KILL 31964609; |
-
| KILL 31964611; |
-
…...
-
| KILL 31966619; |
-
| KILL 31966620; |
-
+------------------------+
-
991 rows in set (0.02
sec)
- root@localhost >
4.执行上面生成的KILL脚本
-
root@localhost > source /tmp/a.txt
-
Query OK, 0 rows affected (0.00
sec)
-
Query OK, 0 rows affected (0.00
sec)
- ……
本文介绍了一种通过SQL查询批量获取并终止指定用户在MySQL中所有进程的方法。具体步骤包括使用SQL查询从information_schema.processlist中筛选出特定用户的进程ID,并将这些ID写入外部文件,然后通过source命令执行该文件来实现批量kill操作。
801

被折叠的 条评论
为什么被折叠?



