我有一个 shell 脚本来在 mysql 数据库中执行一些查询并处理结果并相应地发送邮件。该脚本每 15 分钟运行 24X7。在 shell 脚本中,我只是使用命令连接到数据库 'mysql -uusername -ppassword 数据库 -s -N -e "此处有一些查询"
我想知道的是,这个脚本是否必须对数据库连接泄漏做一些事情,因为我永远执行这个脚本。 当我执行以下查询时,我可以看到每次 Connections 值每 15 分钟增加 1。 显示状态,如“%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 |
+----------------------------------------+-------+
它会在某个时间点崩溃吗?因为值(value)永远不会下降。我知道该值表示数据库存在的连接总数。但是 Max_used_connections 保持不变。 或者有没有办法从 shell 脚本关闭数据库连接?
最佳答案
作为 MySQL 文档 connections server status variable说:
The number of connection attempts (successful or not) to the MySQL server.
因此,这是一个统计数字,显示自上次重新启动 MySQL 服务器以来的连接尝试次数。
threads_connected status variable显示当前打开的连接数(在您的情况下为 14)。如果此状态变量等于 max_connections server SYSTEM variable ,然后您将开始收到连接过多的错误消息。
关于mysql - mysql 数据库连接过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38242343/