终止空闲的 mysql 连接
我看到很多连接处于打开状态并且长时间处于空闲状态,例如 5 分钟。
是否有任何解决方案可以在不重新启动 mysql 服务的情况下从服务器终止/关闭它?
我正在维护旧版 PHP 系统,无法关闭为执行查询而建立的连接。
我是否应该将 my.cnf 文件中的默认超时值减少为 8 小时?
# default 28800 seconds
interactive_timeout=60
wait_timeout=60
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
手动清理:
您可以杀死 processid。
但是:
错误(或网络服务器,检查
错误日志)
让他们去吧。
自动清理服务;)
或者您可以通过在
wait_timeout
和interactive_timeout
设置为:(
也可以在配置文件中设置,以便服务器重新启动时使用)
但是您正在治疗症状而不是根本原因原因 - 为什么连接打开?如果 PHP 脚本完成,它们不应该关闭吗?确保您的网络服务器没有使用连接池...
Manual cleanup:
You can KILL the processid.
But:
errors (or the webserver, check the
error logs)
leave them be.
Automatic cleaner service ;)
Or you configure your mysql-server by setting a shorter timeout on
wait_timeout
andinteractive_timeout
Set with:
(and also set in your configuration file, for when your server restarts)
But you're treating the symptoms instead of the underlying cause - why are the connections open? If the PHP script finished, shouldn't they close? Make sure your webserver is not using connection pooling...
我没有看到任何问题,除非您不使用连接池管理它们。
如果使用连接池,这些连接将被重新使用,而不是启动新连接。所以基本上,保留开放的连接并重新使用它们比每次重新创建它们的问题要少。
I don't see any problem, unless you are not managing them using a connection pool.
If you use connection pool, these connections are re-used instead of initiating new connections. so basically, leaving open connections and re-use them it is less problematic than re-creating them each time.