我有一个shell脚本在mysql数据库中执行一些查询并处理结果并相应地发送邮件。脚本每15分钟运行24X7。里面的shell脚本我只是连接到数据库使用命令 “MySQL的-Uusername -Ppassword数据库-s -e-N‘有些查询到这里’太多的数据库连接mysql
所有我想知道的是,这是否脚本必须做一些与db连接泄漏,因为我永远执行此脚本。 当我执行以下查询时,我可以看到每次Connections值在每15分钟内上升一次。 显示状态,如'%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 |
+----------------------------------------+-------+
它在某个时间点崩溃吗?因为价值永远不会下降。我知道该值表示出现在db的连接总数。但是,Max_used_connections保持不变。 或者有没有办法从shell脚本关闭数据库连接?
您必须正确关闭每个连接 – JYoThI
您不妨考虑使用MySQL事件来避免连接。读这个。 https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html –