Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We're releasing a site in a couple of weeks that has been developed on a local machine but now when were testing on dev server we get

MySQL error 'max_user_connections'.

We have talked to the host company (biggest in sweden) and they say that we don't close our connections properly. But the thing is that we user the EXACT same code on another host where it works. And I also added

echo "closed"; 

in the database_close function so that now in the very bottom of very page there is "closed". To me this means that we do close the connection, anyone got any idea of what could be wrong? We connect through the PHP PDO function and closes it by setting it to 'null', all according to the manual.

share|improve this question
You can check by using "mysql> SHOW PROCESSLIST;". Are you seeing excessive connections? – obfuscurity May 17 '10 at 0:19
try setting it to NULL, not null.… shows it as NULL, though there probably isn't a difference. also, when you attempt to close the connection, maybe look at the value, i.e. print the value of your DB handle to see that it /is/ 'NULL' and not an open connection. – cpbills May 17 '10 at 2:43
Now I'm setting the connection to NULL and not null, still doesn't work. The SHOW PROCESSLIST shows there is a lot of connections in sleep mode piling up. But on my local machine they don't. How do I prevent connections from piling up here? – gust1n May 17 '10 at 8:13

There's soemthing about PHP in a website which means the MySQL connection thread is not thrown away even though you've torn down the socket cleanly; it still hangs around waiting for it to be reaped.

You want to look at your setting for wait_timeout. On default installs, this is insanely long. A website will only need this to be about 20 seconds. You will probably also want it this low if you're using persistent connections.

share|improve this answer

If your using PHP .. try using


Depending on the version of PHP this may help, prior to 5.3 the function didn't require a link identifier.


share|improve this answer

If you're on a shared hosting server then it's probably some other site affecting the shared mysql server. Make sure that's not the case.

share|improve this answer

If you do call mysql_close at each script, then, it should be a problem of your hosting provider, not yours.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.