How can I fix "error establishing database connection" ?

Posted August 5, 2015 16.4k views

I use 512 ram and have 2 websites on Digital ocean and Here I use Webuzo as my panel. The problem comes when I couldn’t open my two sites on wordpress. Error establishing database connection when I tried to open my sites. Please help me.. What should I do?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
7 answers

Have you checked the logs for mysql?


# cat /var/log/mysql.err
# cat /var/log/mysql.log


# cat /var/log/mysqld.err
# cat /var/log/mysqld.log


# cat /var/db/mysql/`hostname`.err
  • Thank you, Now I have fixed the problem. The problem actually happened was mysql was on off mode, then I tried to switch it on..I have a question, how many websites can digital ocean accommodate with 512mb ram?

You might want to check /var/log/syslog for “Out of memory” message as described here:

How to Fix WordPress ‘error establishing a database connection’

  • well I don’t know exactly with my Droplet, I have only 1 website but I don’t understand why it wastes 25 GB diskspace seeing that it is impossible to waste more diskspace because my site is only full of article, can you explain and solve it?

Thank you Jsamuel, now I get new knowledge..I hope we can share our knowledge each other.

Problem solve with this code.. Very simple :)

sudo start mysql

something else for others to consider…

After I upgraded my Wordpress one-click install to use 2gb I was getting the same results....after a day I had to reboot my droplet to get my WP site running normally.
I then took a look at the apache access.log file and noticed a constant POST to xmlrpc.php from some IP Address.

I did two things to fix this…

  1. I updated iptables to drop the offending IP Address

  2. I restricted access to xmlrpc.php (via apache vhost file) to deny from all; I believe this also disables you from using the mobile app to update your wordpress site as well as other 3rd party services to update WP be careful doing this

Now the problem has gone away :)

There might be some other steps you can do to prevent these type of attacks but these two things worked really well for me. Check your logs to make sure someone is not trying to brute force their way in.

You can use this script to restart your server whenever there is database connection error.

I really don’t understand. Can you help me?