Forum Moderators: coopster

Message Too Old, No Replies

mysql_connect(): Too many connections

HELP! PHP errror - site down

         

adammc

10:21 am on Sep 21, 2005 (gmt 0)

10+ Year Member



Hi,
I just tried to visit my site and got the following error:

Warning: mysql_connect(): Too many connections in /home/httpd/vhosts/example.com/httpdocs/connect.php on line 2
Too many connections

Can ANYONE please tell me whats happenned and how to fix it?

[edited by: jatar_k at 4:38 pm (utc) on Sep. 21, 2005]
[edit reason] no urls [/edit]

kees mekhalel

10:27 am on Sep 21, 2005 (gmt 0)

10+ Year Member



Can you just put the code on the connect.php

and modify the username and password and the database name in this file

according to your code we will get the answer

dragonthoughts

10:31 am on Sep 21, 2005 (gmt 0)

10+ Year Member



It is possible that you have exceptionally high traffic on your site, however it is more likely that there connections to your database have been left open.

From a database techie perspective, there are some standard practices.

This general database advice may help you.

Use your database admin tools to:

1) Check if the mysql server is running - if it isn't get it running

2) Close all connections, if you can

3) Stop and restart the mysqlserver if you can't drop the connections

In the future, review your code

4) Check that your PHP code and any other tools always close connections - many database servers require this, and it is good practice.

adammc

10:39 am on Sep 21, 2005 (gmt 0)

10+ Year Member



I take it this error can only be corrected by my hosting provider.

And its just a waiting game, Can i fix it from PHP myadmin?

I guess I learnt a valuable lesson from this : To always close the database connection when doing a query.

:(

Romeo

10:43 am on Sep 21, 2005 (gmt 0)

10+ Year Member



Hi Adam,

it is what the error message says: the database cannot accept more connections, all connection slots are in use otherwise. Several things to check:
-- is your own application OK? Does your application open persistent connections, which aren't closed? Use mysql_connect() instead of mysql_pconnect() unless you have a good reason to do so.
-- have you got more users then ever?
-- can you increase the max_connections system variable, or has it been increased up to its end already (its default value is 100)?
-- Have you looked in the manual for further details:
[dev.mysql.com...]

If it is your own server, then you can look into these things and try to fix and correct.
If you are on shared hosting, you need your hoster to fix this -- perhaps other shared hosting customers started to eat up more connections than they should ... (common hosting error: too many customers on one box ...).

Regards,
R.

adammc

10:57 am on Sep 21, 2005 (gmt 0)

10+ Year Member



My site is back up online...

I just got an email from my host saying:

Thanks for letting us know. I have fixed the problem. Please let me know if you see this occurring again.

Maybe it wasnt my fault?

jatar_k

4:42 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you usually have a set number of connections to mysql via your host, if you have them all used up, no one can create a new one until one dies.

sometimes a server problem can cause the same error, mysql maxes out and then silently dies but apache doesn't know and mysql can't release connections because it is having a little "rest". Usually restarting mysql and apache fixes it.

take a look at Romeo's recommendations

the other thing is to ask your host if you have a set limit, just so you know.

AlexK

7:20 pm on Sep 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



dragonthoughts:
Check that your PHP code and any other tools always close connections

The default action in PHP is to close all open database connections at end of script, so this should (one of those weasel words) never be a problem. Having said that--being a belt 'n' braces guy--I always put a mysql_close() in there.

I've hit this problem on my server, and it has always proved to be a hardware problem, exacerbated by one of the MySQL default settings (wait_timeout which, from memory, is 28,800 secs!) (that means that all blocked threads hang around for hours before they die). There are 3 defaults which are worth changing globally:

# foll to prevent continuous new-thread spawning
# added by Alex 17 Oct 2003
interactive_timeout = 30
thread_cache = 8
wait_timeout = 30

The hardware problems, btw, were bad memory (causing DB corruption) then, later, a full partition.

tgkrishna

1:17 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



My experiance here:
some times i faced this warning : mysql_connect(): Too many connections.

Then i entered in to SQL of my webhosting, and find that, there is no data / nill (nothing is there).

The next day everything is "O.K."/all correct.
I opened my site well.

why is this?

dreamcatcher

2:38 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you on a shared server? I`ve had this several times. It could be someone else`s website thats causing the problem. Have you contacted your host?