简体   繁体   English

调试MySQL:连接过多

[英]Debugging MySQL: Too many connections

After we deployed the new version of our ASP.NET C# app with a MySQL DB we are having issues with the connections. 在将新版本的ASP.NET C#应用程序部署到MySQL数据库之后,连接出现了问题。

Yesterday I got the "Too many connections" error and I'm watching the open connections with SHOW FULL PROCESSLIST and they keep increasing during the day. 昨天,我收到“连接过多”错误,并且正在使用SHOW FULL PROCESSLIST监视打开的连接,并且它们在白天一直在增加。

Is there a good way to figure out where our bug could be? 有没有一种好的方法可以弄清楚我们的错误可能在哪里? Like checking the last query that a sleeping connection made? 像检查睡眠连接所做的最后一个查询一样?

确保您的应用程序正确关闭了与数据库的连接。...如果您的应用程序未关闭连接,则将收到上述错误

Connection pooling usually solved this problem. 连接池通常可以解决此问题。 In your case, connections seem to stay open much too long, which means that in some branches of your software, there's not definitive finally that closes the connection after it has been used. 对于您而言,连接似乎保持打开的时间过长,这意味着在软件的某些分支中,最终没有确定的条件可以在使用完连接后将其关闭。 It's especially useful to diagnose problematic connection usage at a central point, because it can keep an eye on the number of open connections at any given time and maybe alert somebody to make a dump to analyze later. 在中心点诊断有问题的连接使用情况特别有用,因为它可以随时关注打开的连接的数量,并且可能会提醒有人进行转储以供以后分析。

You could also increase the number of connections allowed to your MySQL instance. 您还可以增加允许与MySQL实例的连接数。 The settings in your my.cnf is "max_connections". my.cnf中的设置为“ max_connections”。

Lastly, if you want you can try to decrease the "wait_timeout" or "interactive_timeout" properties of your instance. 最后,如果您愿意,可以尝试减少实例的“ wait_timeout”或“ interactive_timeout”属性。 These settings regulate atomatic closing of connections after certain amounts of time. 这些设置会在一定时间后调节连接的原子关闭。

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

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