监控 mysql 上使用的连接以调试“连接过多”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2453308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Monitoring used connections on mysql to debug 'too many connections'
提问by Nir
On LAMP production server I get the 'too many connections' error from MYSQL occasionally, I want to add monitoring to find if the reason is that I exceed the max-connections limit.
在 LAMP 生产服务器上,我偶尔会从 MYSQL 收到“连接过多”错误,我想添加监控以查找原因是否是我超出了最大连接数限制。
My question: How can I query from mysql or from mysqladmin the current number of used connections? (I noticed that show status gives total connections and not the currently used ones.)
我的问题:如何从 mysql 或 mysqladmin 查询当前使用的连接数?(我注意到 show status 给出了总连接数,而不是当前使用的连接数。)
采纳答案by titanoboa
A very powerful tool to monitor MySQL is innotop
. You can find it here:
监视 MySQL 的一个非常强大的工具是innotop
. 你可以在这里找到它:
https://github.com/innotop/innotop
https://github.com/innotop/innotop
In Debian Lenny, it is part of the package mysql-client-5.0 and I guess it is available for other distros as well. It is especially powerful in monitoring InnoDB internals, but provides general monitoring of the server as well.
在 Debian Lenny 中,它是 mysql-client-5.0 软件包的一部分,我想它也可用于其他发行版。它在监控 InnoDB 内部结构方面特别强大,但也提供了对服务器的一般监控。
In "Variables & Status" mode, it monitors the variables "Connections" and "Max_used_Connections" (among others). It displays absolute and incremental values - the latter might give you an idea about the current connections.
在“变量和状态”模式下,它监视变量“Connections”和“Max_used_Connections”(等等)。它显示绝对值和增量值 - 后者可能会让您了解当前连接。
Since innotop provides a non-interactive mode, you can easily build fully automated monitoring by calling innotop from some customized scripts, nagios checks or whatever system you have.
由于 innotop 提供非交互模式,您可以通过从一些自定义脚本、nagios 检查或您拥有的任何系统调用 innotop 来轻松构建完全自动化的监控。
回答by Mahesh Patil
To get total number of concurrent connections allowed by MySQL you should check
要获得 MySQL 允许的并发连接总数,您应该检查
show variables like 'max_connections'
show variables like 'max_connections'
and how many concurrent connections are being used currently can be measured by
以及当前正在使用的并发连接数可以通过以下方式测量
show status like 'max_used_connections'
show status like 'max_used_connections'
You should monitor these variables. If you need a commercial tool which monitors important MySQL metrics you can try MySQL Enterprise Monitor, MONyog etc..
您应该监视这些变量。如果您需要监控重要 MySQL 指标的商业工具,您可以尝试 MySQL Enterprise Monitor、MONyog 等。
回答by álvaro González
SHOW STATUS doesn't display total connections: it displays current connections. You get the too many connectionserror message when the number of open connections (idle or not) surpases the limit established for the server.
SHOW STATUS 不显示总连接数:它显示当前连接数。当打开的连接数(空闲与否)超过为服务器建立的限制时,您会收到太多连接错误消息。
From your comment about SHOW STATUS, I looks like you have many idle connections in your server. That points to misuse of persistent connections; some libraries that claim to support persistent connections do not handle them properly and they tend to open new connections even when there're idle connections available.
从您对 SHOW STATUS 的评论来看,您的服务器中似乎有许多空闲连接。这指向滥用持久连接;一些声称支持持久连接的库没有正确处理它们,即使有空闲连接可用,它们也倾向于打开新连接。
Find out what application is running such queries and configure it not to use persistent connections.
找出运行此类查询的应用程序并将其配置为不使用持久连接。
回答by t0mm13b
It might be easier for you to obtain the MySQL Admin, from that, you can easily monitor where the used connections are coming from. See here on this about the connectionsused...
获取MySQL Admin对您来说可能更容易,从中您可以轻松监控所用连接的来源。有关所用连接的信息,请参见此处...