简体   繁体   English

mysql数据库连接过多

[英]Too many database connections mysql

I have a shell script to execute some query in mysql database and process the results and send mail accordingly. 我有一个Shell脚本,可以在mysql数据库中执行一些查询并处理结果并相应地发送邮件。 The script runs 24X7 in each 15 minutes. 该脚本每15分钟运行24X7。 Inside the shell script I am simply connecting to the db using the command 'mysql -uusername -ppassword database -s -N -e "Some query goes here" 在shell脚本中,我只是使用命令'mysql -uusername -ppassword database -s -N -e连接到数据库,“某些查询在这里”

All I want to know is that, does this script have to do something with the db connection leak, since I am executing this script forever. 我想知道的是,由于我永远执行此脚本,因此该脚本是否必须对数据库连接泄漏进行某些处理。 When I execute the following query I can see that each time the Connections value goes up by one in each 15 minutes. 当我执行以下查询时,我可以看到每次Connections值每15分钟增加1。 show status like '%Con%'; 显示状态,例如“%Con%”;

+----------------------------------------+-------+
| Variable_name                          | Value |
+----------------------------------------+-------+
| Aborted_connects                       | 4     |
| Com_show_contributors                  | 0     |
| Connections                            | 804   |
| Max_used_connections                   | 152   |
| Performance_schema_cond_classes_lost   | 0     |
| Performance_schema_cond_instances_lost | 0     |
| Ssl_client_connects                    | 0     |
| Ssl_connect_renegotiates               | 0     |
| Ssl_finished_connects                  | 0     |
| Threads_connected                      | 14    |
+----------------------------------------+-------+

Does it crash at some point of time?. 它是否在某个时间崩溃? Because the value never comes down. 因为价值永远不会下降。 I know the value indicates the total number of connections present to the db. 我知道该值指示存在于db的连接总数。 However Max_used_connections remains same. 但是,Max_used_connections保持不变。 Or is there a way to close the db connection from shell script? 还是有办法从Shell脚本关闭数据库连接?

As MySQL documentation on the connections server status variable says: 连接服务器状态变量上的MySQL文档所述:

The number of connection attempts (successful or not) to the MySQL server. 与MySQL服务器的连接尝试次数(成功或失败)。

So, this is a statistical number showing the number of connection attempts since the last restart of the MySQL server. 因此,这是一个统计数字,显示自MySQL服务器上次重启以来的连接尝试次数。

The threads_connected status variable shows the number of currently open connections (14 in your case). thread_connected状态变量显示当前打开的连接数(在您的情况下为14)。 If this status variable equals to the max_connections server SYSTEM variable , then you will start receiving too many connections error message. 如果此状态变量等于max_connections服务器的SYSTEM变量 ,那么您将开始收到太多的连接错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM