Error establishing a database connection (WordPress)

Posted May 25, 2014 102.1k views
Hi there, I'm having a really hard time figuring this out... My website shows up "Error establishing a database connection" on occasion. This happens about once a day. As soon as I reboot the droplet, the problem's gone. I've tried adding the following 2 lines in my wp-config file, as suggested on some other forums, but it didn't work: define('WP_MEMORY_LIMIT', '64M'); define('WP_ALLOW_REPAIR', true); From what I read around the web, it seems that 512mb of RAM is perfectly fine for a wordpress multisite, if set correctly - though I'm having a hard time with a single (low content) site, without many plugins. I've also disabled/deleted the plugins that could potentially eat up a lot of memory, such as wp-backup. If you have any suggestions for me, I'd be more than thankful! Please notice that I'm pretty new with all this, and as it's my first time running VPS, I do have a bit hard time understanding how everything works, at the moment...
  • We have about 20 accounts on DigitalOcean and over the past two months ALL OF THEM have been experiencing this issue, even on droplets with 4GB RAM. We’re migrating all of our sites elsewhere…

  • I have the same problem as well. I often restart the server but each time I restart, same thing happen the next day and this is happening 50% of my websites on DigitalOcean. I do have website hosting elsewhere and they works perfectly fine with lower monthly cost.

    I’m moving all my websites elsewhere as well. It’s just ridiculous.

  • I have also experiences this issue over the last week. Does anyone have any idea what might cause this? Anyone got some alternative places to host?

  • Same issue for me! Glad I am no the only one.. i tried swap files and editing wp-config, but no help

  • Same issue here. While the DigitalOcean team has been very helpful, I just can’t get this site to function properly. I am going to have to migrate as well.

  • Show 39 more comments

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
27 answers

EDIT: If you’re fairly certain you’re not suffering from an xml-rpc attack, check out our article about debugging Wordpress database errors.

EDIT: We now have a community article covering xml-rpc attacks!

Hey there,

As @nestchris said, we have started seeing an influx of brute-force amplification attacks, both on our service and the rest of the internet at large. These attacks exploit the XML-RPC functionality in WordPress, as described on

You can see if you are being taken down by this attack by running one of the following two commands on your droplet, depending on which webserver you’re running:

grep xmlrpc /var/log/apache2/access.log
grep xmlrpc /var/log/nginx/access.log

If you get any results there, it should be easy to fix this issue. If you’ve spun up a WordPress One-Click install droplet since Dec 2015, there’s a small config file which you can enable to block such attacks. We don’t enable it by default because it breaks some commonly used plugins (like Jetpack). Here are the commands you can run:

sudo a2enconf block-xmlrpc
sudo service apache2 restart

Alternatively, Jetpack has functionality to block these requests without impacting other plugins. Check out their Protect module.

If you’re running a WordPress droplet older than Dec 2015 and you don’t want to use the Jetpack plugin from Automattic, you’ll need to configure the droplet manually to block requests to xmlrpc.php:

Apache2 (goes inside your VirtualHost config):

<files xmlrpc.php> 
order allow,deny 
deny from all 

Nginx (goes inside your server{} block):

location /xmlrpc.php { 
deny all; 

Alternatively, if you are not having this issue due to an XML-RPC brute force attack, your Droplet might not have enough memory to deal with your traffic reliably. We recommend users run WordPress on a 1GB droplet or larger.

In order to help reduce your memory usage, you’d first want to check for any plugins using a large amount of memory. There are a lot of memory hungry plugins out there! You may also want to optimize your configuration files.

Below are some great resources that we commonly recommend in support tickets, explaining how to do so, depending on your setup:




If none of this works, you may have no choice but to resize to a larger sized droplet that can handle your traffic.

Platform Support Specialist

by Matthew Nuzum
Apache is an amazingly powerful and capable web server. In order to make initial setup as easy as possible, it comes with numerous modules pre-installed. This makes it a great choice for new projects when you need to quickly be productive, but as your site grows you may start to bump into performance problems. This tutorial will cover a few things you should do to optimize performance if you’re running Apache with your Django app.
  • Thanks for this Eris! Good to finally hear from someone about this issue. My droplet was spun up before Dec 2015, and was running Jetpack with protect enabled but I am still encountering the problem, I’m fairly sure there were no traffic spikes either. Will try manually blocking requests to xmlrpc.php though.

    • No problem! If you have Jetpack enabled with Protect, then you should not have to worry about the issue I outlined above. I would not recommend manually blocking xmlrpc.php if you’re using Jetpack, because that will break Jetpack. It also probably won’t do anything.

      If you want, you could verify this by checking your access log as I outlined above, but I would honestly approach this issue as if you’re simply running out of memory. The optimization links towards the end of my post are useful to this end, as are caching plugins (like wp super cache). It could also be that one of your plugins has a memory leak, which is actually fairly common. You may want to disable plugins one by one and see how that affects your memory usage.

      Platform Support Specialist

  • I love you for this! <3

  • If the issue is caused by XML-RPC spam, then another alternative to Jetpack is the Wordpress plugin “All in One WP Security”, which has - in addition to its many other security features - a setting to block XMLRPC (WP Security > Firewall > Basic Firewall Rules > Enable Pingback Protection).

  • Thank you. It was helpful.

  • Hello, I’ve run sudo a2enconf block-xmlrpc before install JetPack, and now I’m getting a error “Your JetPack has a glitch”.
    errors details: “The Jetpack server could not communicate with your site’s XML-RPC URL…”

    I think it’s because it’s blocked. How can I ‘unblock’ it again to install JetPack?


    • You can unblock xml-rpc by running sudo a2disconf block-xmlrpc and restarting apache2 again (sudo service apache2 restart)

  • Alright. I’m literally fuming.

    This is happening CONSTANTLY. As in less than 5 minutes apart.

    I’ve done everything I can find and it is still happening. The site has 0 traffic. It’s literally just gotten started. Please. Tell me what to do… I can’t take any more.

    • If you tried everything, I’d recommend opening a support ticket. This way, a member of our support team can give you advice tailored specifically to your Droplet. It’s possible that this is not related to the XML-RPC issue that many wordpress blogs face.

      • I have opened a ticket and now I am waiting, but in the mean time I can hardly do anything on the site because I must constantly restart the server, and Jetpack keeps emailing me every few minutes about the site going down.

It seems like MySQL is running out of RAM and crashing. You could add swap and see if that helps (, or upgrade your droplet to the next plan so that there's more RAM available for MySQL.
by Etel Sverdlov
Linux swaps allow a system to harness more memory than was originally physically available. Here's how to set up a linux swap file on Ubuntu 12.04
  • Seems to me, that company never fix this to make you move to higer plans. Looking for alternatives to move.

  • One concern with adding swap is that swap is not real memory - its disk. Even the fast SSD disks are an order of magnitude slower than memory can be.

    Consider adding swap as a bandaid to get you through until you can upgrade to a larger size OR optimize your configuration.

As we know, a shared host like Bluehost has more direct control over your server. On DO, you are required to maintain the server, and that means things that you might not need to deal with on other hosts come up here.

I was made aware of this exploit by the DO team.

After implementing the apache.config solution, my problems stopped.

[Apache VirtualHost Config]

<files xmlrpc.php>
order allow,deny
deny from all

This attack is affecting all wordpress sites, but if you were using another host before, you may not have noticed. In my experience with Bluehost, I have had them suspend my account because I was attacked by comment spam, I suspect something similar to that would have occurred in this instance as well.

Unfortunately DO has been very slow to address this issue with the community as it seems everyone is in the dark about it.

  • I believe a community article should be in the works for this. In the meantime, we’ve since updated the base WordPress One-Click to have an easy way to block these attacks. Unfortunately, we can’t enable it by default because it breaks some commonly used plugins (like Jetpack). Anyone who created a WordPress droplet since December 2015 should have this config file that they are able to enable. We recommend it all the time on Support.

    Here are the commands you can run to do so:

    sudo a2enconf block-xmlrpc
    sudo service apache2 restart

    Alternatively, Jetpack has functionality to only whitelist certain IPs for the API. If you have Jetpack Protect enabled, you should not need to worry about XML-RPC attacks.

I have had the same problem and its not a fault of digital ocean. A little bit knowledge in server maintenance is what is actually required.

Ubuntu 14.04

Check if your mysql is running
mysqladmin -u root -p status

and then enter your mysql root password

if it’s running properly u get a message
Uptime: 4 Threads: 1 Questions: 62 Slow queries: 0 Opens: 51 Flush tables: 1 Open tables: 45 Queries per second avg: 15.500

or an error message

mysqladmin: connect to server at ‘localhost’ failed
error: 'Can’t connect to local MySQL server through socket ’/var/run/mysqld/mysqld.sock’ (2)’
Check that mysqld is running and that the socket: ’/var/run/mysqld/mysqld.sock’ exists!

This error message is the reason for you to get Error establishing a database connection

fix this by starting the mysql with the command
sudo start mysql

I hope my solution helps you in fixing your issue.

I am not a real tech guy, but I was able to fix our website,, by turning off the power of the droplet and turning it on.

please tired all week my site falls due this connection error will not change cloud service more

Problem solve with this code.. Very simple :)

sudo start mysql

Can someone recommend a good Wordpress host because this is a fucking disaster.

I Have done all of these things; spoke to support who kindly suggested it ; and i am STILL getting this issue. I am thinking about leaving DO because this is a business I am running and random error establishing a connection shouldn’t be happening, especially if I go to sleep and find out at 1AM it went down and didn’t find out until I got up at 7AM! This has been going on for now three months. I also upgraded and I STILL have the issue. Please DO , fix it, I have tried on my end and it is STILL happening. I am frustrated about it. I have opened a support ticket and sill no fix.

I can not solve this error somehow, I tried almost every method. I started having this problem on better performance (2 cpu - 2 GB Ram) droplets also..

Previous 1 2 3 Next