当前位置: 代码网 > it编程>数据库>Mysql > mysql连接数清理方案

mysql连接数清理方案

2025年10月11日 Mysql 我要评论
mysql连接数清理查看mysql连接进程列表show full processlist;查看mysql最大连接数show variables like '%max_connections%';查看当

mysql连接数清理

查看mysql连接进程列表

show full processlist;

查看mysql最大连接数

show variables like '%max_connections%';

查看当前使用的连接数

show global status like 'max_used_connections';

设置禁触休息多少秒后清除连接

set global wait_timeout=10000;

set global interactive_timeout=300;

杀掉空闲时间在600秒以上的链接

拼接得到kill语句

select concat('kill ',id,';') from information_schema.`processlist` 
where command = 'sleep' and time > 600;

杀掉处于某个状态的链接

拼接得到kill语句

select concat('kill ',id,';') from information_schema.`processlist`
where state = 'sleep';

杀掉某个用户发起的链接

拼接得到kill语句

select concat('kill ',id,';') from information_schema.`processlist`
where user = 'user';

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com