MySQL 终止睡眠连接 [英] MySQL kill sleep connections

查看:89
本文介绍了MySQL 终止睡眠连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库似乎有近 100 个睡眠"连接,我相信摆脱它们会更好.我找到了以下脚本,它可以帮助我从命令行分析数据库中的所有表.有没有人知道一种类似的可以杀死所有睡眠"连接的班轮?

My DB seems to have almost 100 "sleep" connections and I believe it would be better to get rid of them. I have found the following script which helps me analyze all tables in a DB from the command line. Does anybody know of a similar one liner which can kill all "sleep" connections?

mysql -p -D<database> -B -e "SHOW TABLES" \
| awk '{print "CHECK TABLE "$1";"}' \
| mysql -p -D<database>

推荐答案

您可以将 wait_timeout 变量设置为比默认值更短的时间,一旦连接超过此时间值,它就会终止连接.

You can set the wait_timeout variable to a shorter time than the default and it should kill off the connections once they exceed this time value.

从我读到的内容来看,存在一些错误,连接仍然会随机挂起,尤其是在负载下,但 wait_timeout 变量将是开始的地方.

From what I've read there is some bugginess and connections will still randomly hang around, especially under load, but the wait_timeout variable would be the place to start.

这篇关于MySQL 终止睡眠连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆