Error Establishing Database Connection

February 20, 2018 1.2k views
Ubuntu WordPress Ubuntu 16.04

Hello there, Can someone please help me, I always got this Error Establishing Database Connection on my website and it almost appears every day. I am on 512mb / 20GB disk Plan ( Droplet) and my traffics range is only 500-800 traffics daily. Can someone please tell me how to fix this issue? Almost getting this issue from the beginning I created my website. My website Plugins posted below:

Complete Analytics Optimization Suite (CAOS)
Easy Social Share Buttons for WordPress
EasyRecipe Plus
Envato Market
Facebook Pixel
Instant Articles for WP
Jetpack by
jQuery Pin It Button for Images Pro
Nginx Helper
W3 Total Cache
Wordfence Security
WP Smush
Yoast SEO

1 Answer


You’re getting that error because MySQL is crashing and so WordPress is no longer able to connect to it. MySQL and WordPress, especially with a lot of plugins installed, both require a lot of memory and a 512MB Droplet is not enough to handle those requirements.

I would recommend upgrading to a 1GB Droplet first—we have recently introduced new plans so you will be able to do that without any additional cost. But, you might want to also consider upgrading to a 2GB Droplet to make sure that both programs have some room to breathe.

Additionally, check out this tutorial on setting up Redis Caching. It is a bit old but the same instructions should work, though you might have to replace php5 with php7:

by Scott Miller
Redis is an open-source key value store that can operate as both an in-memory store and as cache. Redis is a data structure server that can be used as a database server on its own, or paired with a relational database like MySQL to speed things up. For this tutorial, Redis will be configured as a cache for WordPress to alleviate the redundant and time-consuming database queries used to render a WordPress page. The result is a WordPress site that is much faster.
  • can you show me where and how to upgrade into 1GB droplet?

    • by Melissa Anderson
      Resizing your servers can be an effective way of increasing their capacity, by allowing them to utilize more memory (RAM), CPU, and disk storage. The ability to resize a server, also known as vertical scaling, can be useful in a variety of situations that prompt the need for a more powerful server, such as if your concurrent user base increases or if you need to store more data. In this tutorial, we will show you how to resize your server, also known as a droplet, on DigitalOcean.
      • also is it safe to have redis and w3 total cache running at the same time? or i will just disable and uninstall the w3 total cache?

      • I have already resized my droplet into 1GB, Do I have to edit something at my side after upgrading?

        • All you need to do is restart your Droplet after upgrading. You don’t need to reconfigure anything.

          It appears that W3 Total Cache supports Redis, so once you’ve installed Redis using apt-get, log in to your WordPress admin panel, go to Performance -> General Settings, and configure Redis in the Object Cache section.

      • @kamaln7 hey mate, I already upgraded my Droplet into the 3GB plan but still getting this Error Establishing Database Connection. Can you please help me what to do? I already followed some instructions here but still no luck :(

  • @kamaln7 also when I tried to reboot my Droplet, my website becomes offline and can’t be accessed and need to restore the backup.

    • Is MySQL configured to start on boot? If you start it manually, does it still crash now that you’ve upgraded your Droplet?

      sudo systemctl start mysql

      To configure MySQL to start automatically on (re)boot, run:

      sudo systemctl enable mysql
      • hey mate, it says - sudo: systemctl: command not found

      • is it possible that the old files and settings on my old website / domain is connected into my new website / new domain thats why i am getting that error everytime i deleted the old website / domain files?

        • Sorry, depending on your Ubuntu version you might have to use these command instead:

          sudo service start mysql
          sudo update-rc.d mysql defaults

          What do you mean by old website? Where is that hosted? On the same Droplet? Also, you have a lot of plug-ins installed—one thing you could do is disable all of them and enable them one by one every few minutes or so and monitor your CPU and RAM usage using htop. It’s possible that a faulty plug-in is causing this.

Have another answer? Share your knowledge.