[英]MYSQL Too many connections error will not go away
I'm getting a MySQL "Too many connections" error in a C++ program running on Ubuntu Linux. 我在Ubuntu Linux上运行的C ++程序中遇到MySQL“Too many connections”错误。
This is the code that gets the error (it's inside a method that returns the mysql error, if any): 这是获取错误的代码(它在一个返回mysql错误的方法中,如果有的话):
MYSQL connect;
mysql_init(&connect);
if (!mysql_real_connect(&connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0))
{
return mysql_error(&connect);
}
This code keeps returning the string "Too many connections." 此代码不断返回字符串“Too many connections”。
I'm wondering if this is actually some other error. 我想知道这是否真的是其他错误。 This program has been working for months before I got this error. 在我收到此错误之前,该程序已经工作了几个月。 When the error first appeared it was because I had run the program against several thousand updates/reads and so yes, it's highly likely that I used up the available connections. 当错误首次出现时,是因为我已经针对数千个更新/读取运行程序,所以是的,很可能我用完了可用的连接。 The problem is, I can't find a way to release them, if that's what it is. 问题是,我找不到释放它们的方法,如果它就是这样的话。
Here is what I have tried: 这是我尝试过的:
It has been over 12 hours since this error first appeared, so if it is the connections then nothing is being reset/released. 自此错误首次出现以来已超过12小时,因此如果是连接,则不会重置/释放任何内容。 I would have thought rebooting the machine would have released something. 我本以为重启机器会发布一些东西。
See C.5.2.7. 见C.5.2.7。 Too many connections. 太多联系。
View all MySQL connections. 查看所有MySQL连接。
netstat -apn | grep mysql | grep -i established
max_connections=#
in /etc/mysql/my.cnf or restart MySQL with --max_connections=#
在--max_connections=#
增加max_connections=#
或使用--max_connections=#
重新启动MySQL Make sure you close connection when you are done with them. 确保在完成连接后关闭连接。
Consider reusing connections or connection pooling. 考虑重用连接或连接池。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.