From time to time I get this error message when I try to go to my site which has acces to my database. (all pages on my site):
Warning: mysql_connect(): Too many connections in /srv/www/htdocs/webxxx/html/xxx.php on line 6
database unavailable: :
Why is this happening? And is there anything I can do about it?
This is really annoying, because no visit to the site is possible during that time.
Thanks in advanve for your advice!
from http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html
A.2.6. Too many connections
If you get a Too many connections error when you try to connect to the mysqld server, this means that all available connections are in use by other clients.
The number of connections allowed is controlled by the max_connections system variable. Its default value is 100. If you need to support more connections, you should restart mysqld with a larger value for this variable.
mysqld actually allows max_connections+1 clients to connect. The extra connection is reserved for use by accounts that have the SUPER privilege. By granting the SUPER privilege to administrators and not to normal users (who should not need it), an administrator can connect to the server and use SHOW PROCESSLIST to diagnose problems even if the maximum number of unprivileged clients are connected. See Section 13.5.4.19, SHOW PROCESSLIST Syntax.
The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform. Linux or Solaris should be able to support 500-1000 simultaneous connections, depending on how much RAM you have and what your clients are doing. Static Linux binaries provided by MySQL AB can support up to 4000 connections.
Thank you.
I´m wondering how tjis can happen. My site is visited by me and 5 friends per day. So why is this happening?
Are there errors in my script? I do NOT use persistent connections.
Is it possible that a missing close of a connection can lead to this problem?
Or is it because I am on a shared host and also the Connection to the mysql db are shared?
Make sure you're closing your connections when you're done with them. Otherwise you may be leaving a bunch of dead connections open.
Happened to me in a C# site I was working on. Of course, Microsoft doesn't give you a nice relevant error like that.
[edit]
Is it possible that a missing close of a connection can lead to this problem?
Or is it because I am on a shared host and also the Connection to the mysql db are shared?
Could be either.
Ok. Thanks. I thought I closed everything. This didn´t happen for quite a while.
But after this I will have to check all the scripts again.
But if they are ok and everything is closed properly I probably can´t do anything about this error, right?
[edit]
missed your edit. if it could be a problem of the shared host, I can´t do anything about it.
I probably can´t do anything about this error, right?
"If you need to support more connections, you should restart mysqld with a larger value for this variable."
If you can't, you are right. You can't do anything else than asking your FAI to upgrade the number of connection, ask him if connection are also mutuals and my bad, I think it's all.
The site has been down a few times today.
I guess all this is not related to my site but a server issue.
If I want to change hosts is it possible to keep my internetadress? The Hosting service registered it for me so I doubt that it is possible but that would be very uncool because I have to give up the adress when I decide to change hosts.
If it's in their name, there's nothing you can do but ask them politely. Keep in mind with webhosting, you get what you pay for. A few dollars per month usually means you are on an overloaded server or with a company that is run out of a 15 year old's basement.
or with a company that is run out of a 15 year old's basement.
Or the 15yr olds company is hosted in a crappy datacenter with a crappy version of Fedora installed.
Hey, I'm 16 and its RedHat.
Hey, you were 15, and RedHat is worse than fedora since RedHat is old and unmaintained
I'd prefer Gentoo or similar, but I don't have much of a choice (considering I use plesk, there are no good free alternative to plesk, so I'm locked to which distros Plesk supports through my ISP as my ISP must install it).