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)
参考Mass killing of MySQL Connections
查找可导出路径
show variables like '%secure%';查看 secure-file-priv 当前的值是什么
本文介绍了一种通过SQL查询批量生成并执行终止MySQL进程中特定用户会话的方法。利用concat函数构造包含KILL命令的字符串,并使用into outfile将结果导出到文件中,最后通过source命令执行该文件中的命令。

1万+

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



