carpediem
By:
carpediem

Wordpress Error Establishing Database Connection

February 12, 2017 396 views
WordPress

Can someone please help me with this, my Wordpress website always get this Error almost 2 times a week with Error Establishing Connection. I don't know how to fix the issue, tried to ask for admin support but still the error is there.

This is the picture of the error - https://i.gyazo.com/6e282a49bd82c3a775e924ef657793eb.png

This is the plugins i am using on my wordpress site -
https://gyazo.com/ebcc16a7b04151cc28a87c76fc364106
https://gyazo.com/c30f807fd552e0d658435a616527b7cb

please i need your help, my website almost down for 20mins or more depends on the time i check and reboot the droplets.

4 Answers

@carpediem

What size is your Droplet?

If it is MySQL that is crashing and this happens to be a 512MB Droplet, that may be the reason why. While it can be done, to an extent, running Apache/NGINX, MySQL/MariaDB, and PHP/PHP-FPM on one server with only 1 CPU and 512MB of RAM is increasing difficult and requires that you know how to tweak and tune the configuration to work within such constraints.

For a standard LAMP or LEMP Stack, I'd recommend 1GB minimum, 2GB preferred.

First, in my experience, a 512 MB/20 GB droplet can easily support a LAMP or LEMP stack for even a moderate load Wordpress site. Tweaking the configuration does help -- see tutorials on DO for that, or here https://deliciousbrains.com/hosting-wordpress-setup-secure-virtual-server/.

The problem that you describe is quite common and I would start to troubleshoot it by checking the database connection information in your wp-config file. If that is all okay you may want to check your MySQL or MariaDB install (whichever you use). Typically, at least for me, it quite often comes down to user permission and privilege issues at the database level, particularly for the "root" user account. It's a bit beyond the scope to go into details here so have a google around for more information -- there is a lot of information available.

@carpediem

That's what I originally thought judging by what you've said regarding the error noted.

As I said in my previous response, it is possible to run a working stack on 512MB, but it's not quite as easy as set and forget. You have to constantly tweak and tune configuration for all services running (NGINX, MySQL/MariaDB, PHP-FPM, Redis/Memcached, etc).

Plugins

From what I can see, you have ~30 plugins installed and active. That's going to be taxing on limited resources.

The WP-Smush and EWWW plugins are redundant and taxing on the CPU as they both require CPU to handle smushing/compressing your images down.

The more images you upload and are processing, the more intensive. You don't need them both, so I'd pick one or the other.

Caching

If you have Redis/Memcached installed, that's going to chew up ~32-128MB of your RAM at any given time. The defaults are 64MB. Unless you need these services and are planning to run multiple servers, you'd be better off using PHP's OpCode Caching. In most all cases, it's going to be faster than Redis or Memcached as it's handled by PHP natively and doesn't need to be offloaded to a service.

Now, if you were running NGINX on one Droplet, PHP-FPM on another, your database on another, etc -- (i.e. clustering) -- then yeah, Redis or Memcached would be perfect.

Recommendations

I would recommend dropping Redis/Memcached and using PHP's OpCode Caching for object cache. I would also choose either WP-Smush or EWWW, but not both. Additionally, reduce your plugins down to those you absolutely need -- deactivate anything you aren't using or don't need.

Beyond those recommendations, it's more of a challenge of tweaking and tuning, or upgrading your Droplet so that you have more RAM available. As noted above, I recommend 1GB minimum, but at least 2GB if you're going to use this as a production Droplet that receives traffic so that you have the room you need to grow.

  • this is the memory usage of my droplet / website

    total used free shared buffers cached
    Mem: 489 447 42 64 27 189
    -/+ buffers/cache: 230 259
    Swap: 1023 19 1004

    as a newbie, i remember i adjusted my memory limit using a code up to its max size 512 mb but now i don't know how to adjust it again

Have another answer? Share your knowledge.