[英]MySQL: "Too many connections"?
I'm getting this error:我收到此错误:
Warning: mysql_connect() [function.mysql-connect]: Too many connections in /home1/host/public_html/employee/message/config.php on line 4
警告: mysql_connect() [function.mysql-connect]:第4行/home1/host/public_html/employee/message/config.php中的连接太多
Could no connect to database.
无法连接到数据库。 Too many connections
太多联系
No one else is on my site at the moment.目前没有其他人在我的网站上。 I'm the only one.
我是唯一的。
I do have a lot of AJAX, but the connections close after they're done.我确实有很多 AJAX,但连接完成后会关闭。 That is why I don't understand why I have a
too many connections
error.这就是为什么我不明白为什么我有
too many connections
错误。
您可以尝试通过查询您的 MYSQL 来查看在您执行 AJAX 请求后连接是否正确关闭吗?
Are you using a webserver (IIS, Apache, etc)?您是否使用网络服务器(IIS、Apache 等)? They often pool the connections and hang on to them for a while to keep queries running fast.
他们经常将连接池化并挂起一段时间以保持查询快速运行。 If you are, try restarting your webserver app (in IIS, Start -> Run "iisreset") and see if that frees it up.
如果是,请尝试重新启动您的网络服务器应用程序(在 IIS 中,开始 -> 运行“iisreset”)并查看是否可以释放它。
This issue is due to Multiple connection instance are active at a time.此问题是由于多个连接实例一次处于活动状态。 Use Singleton object for Connection object creation.
使用 Singleton 对象创建 Connection 对象。
Make sure you close all existing database connections before making another connection.确保在建立另一个连接之前关闭所有现有的数据库连接。 Do this by using the code
$mysqlConnectionName->close();
使用代码
$mysqlConnectionName->close();
来做到这一点or mysql_close($mysqlConnectionName);
或
mysql_close($mysqlConnectionName);
I had the same issue in a custom framework that I am using.我在使用的自定义框架中遇到了同样的问题。 The solution was to create one connection per http request (new mysqli).
解决方案是为每个 http 请求创建一个连接(新的 mysqli)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.