WordPress – Error Establishing Database Connection (and how I solve it)

error_establishing_database_wordpress

Unlimited Error Establishing Database Connection Works

13th May 2015 Update: With the high volume of spambot attacks on this website since late April 2015, I noticed that it can crash the MySQL process easily when it start to run out of RAM to handle the amount of connections generated by the spambot. I recommend disabling comments after you’ve restart the MySQL process to ensure a smoother WordPress operation until you upgrade your server specs or beef up security to reduce the numbers of spambot attacks.

After setting up WordPress as a CMS for my site, I love using it and of course there is potential problem that you will encounter that range from trivial to catastrophic problem that render the site useless.

Still nothing beat the dreaded Error Establishing Database Connection after operating it for nearly 2 years.

Yes this problem start to pop up more frequently lately for me so read on to learn more how you can solve it.

One way or another way

The dreaded message can be really annoying as this happens frequently for me after migrating to my current host aka DigitalOcean. Obviously the problem does not lie on them as you need to setup your own VPS at DigitalOcean and any problem is 99.99% the admin fault like the writer himself ( ^.^;;).

So the thing is many solutions suggested by others don’t really work well for me including WordPress official documentation.

What works for me (remember this solution is for those running their own server and not shared hosting) is to login to your server and restart the MySQL database service.

Depending on your server OS, the procedure varies among the OS so I’ll list down the steps for those running Ubuntu on their server. As usual, you must know how to setup PuTTY to access to your server… or here’s a great guide in using PuTTY by DigitalOcean.

The command you’re looking for will be:

sudo /etc/init.d/mysql restart

Ok in case that doesn’t work, you can try the following command:

sudo start mysql

sudo restart mysql # The service must be running

sudo stop mysql # The service must be running

I suggest stopping MySQL service first then start it again as that will ensure the service is properly terminated from the memory.

This solution does not solve my problem!

Hopefully if all goes well, you WordPress site should be able to load without any issue. If the problem still persists, then you can try the alternative methods suggested by WordPress official docs.

OR you can always google about it and navigate your way to the solution that will work for you.

It took me quite a number of hours to wrestle this problem into oblivion and I know 0.0000001% in using PuTTY and Ubuntu.

Either way all the best in solving this problem!