johnnietheblack johnnietheblack - 8 days ago 10
MySQL Question

How to fix: mysql_connect(): Too many connections

I am getting the following error:

mysql_connect(): Too many connections


It has completely shut down my site, which has been running seamlessly for several years.

Note: I have shared hosting with GoDaddy.

How do I fix this?

ALSO: is there a way to close all connections and restart when on a shared hosting plan?

Answer

Most probably, you have been a subject of a DDoS attack.

People on this forum complain on exactly same thing with exactly same provider.

The answer is this:

VB told me it was a DOS attack - here is their message:

This is not an 'exploit'. This is a DoS attack (Denial of Service). Unfortunately there is nothing we can do about this. DoS attacks can only be fought at the server or router level, and this is the responsibility of your host. Instead of doing this they have decided to take the easy way out and suspend your account.

If you cannot get them to take this seriously, then you should look for another host. Sorry for the bad news.

A possible workaround can be this: if your connection fails with mysql_connect(): Too many connections, you don't quit, but instead sleep() for half a second and try to connect again, and exit only when 10 attempts fail.

It's not a solution, it's a workaround.

This of course will delay your page loading, but it's better than an ugly too many connections message.

You also can come with a some kind of a method which tells bots and browsers apart.

Like, set a salted SHA1 cookie, redirect to the same page and then check that cookie and connect to MySQL only if the user agent had passed the test.