"Error establishing a database connection" on a new WordPress site?

Posted September 4, 2013 41.8k views
Hey. I created a new 512MB droplet, and used the 1-click wordpress install. I added a few plugins, and created just one page. This is a brand new site, and currently has no other content. The website was running fine a few days back, however, when I tried to load it today, I got the message: "error establishing a database connection" I rebooted the droplet through SSH, and the website started working again. A few articles in the DO community point out that this may be due to MySQL crashing because its falling short of memory. So I checked my Google Analytics account to see if there has been a sudden surge of activity on my website, and the only activity was 5 or so visitors a couple of days back. MySQL memory shortage seems like a plausible explanation, but I have difficulty believing that a 512 MB droplet is not enough to run a completely empty wordpress website and serve 5 users. I have a few questions: 1. Is 512 MB really too low to just host a blank site? Should the DB fail with 5 visitors? 2. If not, then what other factors could cause the DB to stop working? 3. How can I check the logs/ or find out for sure what the problem was? 4. Is there any way to keep a track of the droplet's memory usage? Additional information: I installed the following plugins on my WP site: - Better WP Security - Google Analytics for WordPress - WordPress SEO - Microkid's Related Posts - Disqus Comment System - Contact Form 7 - All in one Favicon I also installed a couple of other plugins, but they were deactivated. Also, the "Better WP Security" plugin is configured to create a backup of the WP DB every few days. Please help me out with this. I'd like to prevent my site from failing again.
  • If you have 512MB ram - add 1024MB swap file.

    In tutorial above swap is 256MB. Create 1024MB file like this:
    dd if=/dev/zero of=/swapfile bs=1M count=1000

  • This seems like a common issue. I’ve contacted DO support sever times. First I was told it was due to noisy neighbors, then I was told it might be something wrong on my end. I guess—plugins. My 1gb ram droplet typically uses 5%-10% CPU, then randomly, every 1-4 days, my server gets hit with 80%-100% CPU spike. This is when I receive the database connection error.

    My site has low traffic. I use WP Super Cache to only dump cache once per day. I am also using to manage my WP install. I’ve followed their suggested settings.

    The cache dumping time does not match the CPU spike time.

    It also seems swap is enabled.

    Running sudo swapon -s
    returns the following:
    “`Filename Type Size Used Priority
    /swapfile file 524284 0 -1

    Any ideas?
  • Go here:

    Their WP image has no swap so memory gets used up 100% and causes mysql to crash. I wonder if it’s the same for their other images.

    DigitalOcean #nochill

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.

38 answers
@Dave: Is MySQL running? sudo service mysql status

Was it working fine previously?
Hi Everyone, please I need help:

When i try to access myipaddress/phpmyadmin i get the following error:

phpMyAdmin - Error
The mysqli extension is missing. Please check your PHP configuration. Documentation

I just recently moved 2 sites to the digital ocean droplet (2GB, 40GB Ubuntu droplet) and the frontend of the site is showing error connecting to database.

Please help, very urgent.
We are having the same issue and are thinking about WPEngine to solve these headaches. One suggestion was to use nginix on DO as well.
It can be result of high load and MySQl crash. I use script to check couple of services every 5 minute if they are running, and start/restart them if they don't. You can use "monit" I think there is tutorial here how to install it.
  • Can you give me/us the example script of it? The script to control and check couple of services every 5 minute if they are running, and start/restart the system.


512 droplet is definitely enough to host a wordpress website. Mine is on a 512 droplet, never experienced any issues. I'd suspect the problem might be related to one of the plugins leaking memory.
@Goran: Possibly. Is there any way to check if this is the case, and which plugin could be the culprit?
First I'd check any plugins doing backups. Schedule a backup from the plugin and check if that's the issue. Sometimes backup plugins can use a lot of memory.
Next I'd disable the plugins one by one and test the website performance. If you find a certain plugin to be the one causing the issues, disable it and seek alternative if you must have its functionality.
If you'd like to get a deeper insight I'd install New Relic to check what's consuming memory.
By the way, which php5 modules are you running? Which apache2 modules do you have installed? I'm asking because I don't know which ones are installed using the 1-click install and you may have some modules that are unnecessary.
See here:

also make sure you have swap and if not do it
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
Apache uses a lot of memory by default, especially if you have a lot of plugins/themes installed. This wouldn't leave a lot of memory for MySQL and would cause it to crash.

Try adding some swap to your droplet:
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
@Goran: Thanks for the suggestions. I ended up creating a larger droplet, mainly because I'm certain that I will install more plugins on my site, and some more software on my server.

@Goran, @Kamal: I had an extensive chat with DO support today. They told me that DO VPS no longer support swap. The article is outdated, and is going to be removed.
I was having a the same issue however I have two wordpress sites with no plugins and few visitors. Upgrading to 1GB does resolve the issue but after that I signed up to New Relic and installed their PHP monitoring tool and server monitoring tool. I am still working through the results but it's looking more and more like Apache is the cause of the issue in so far as it after only a few hours it's sucked up nearly all available memory.
I am having the same issue on a new droplet with just a couple of WP plug-ins. Is there a way to monitor the situation and restart MySQL if it's down?
@stas: I recommend adding swap to your droplet (see the links above). That should prevent MySQL from crashing.
I've been having this issue as well - and adding swap hasn't resolved it.
The problem may be due to high memory usage and you may not have created the swap file for efficients memory management. Follow the link to get the procedure to create swap file
Are you guys able to fix the issue? I am facing a similar problem.
Added swap. But how swapped memory gets freed up?

I have a fresh installation of wordpress, on one 512mb droplet, and no traffic or little traffic, First time I have the error in 2 months

-No extra plug ins
-Askimet activated
-No extra themes, only the default twenty fourteen
-I have swap added
-Using webmin

On the other hand I have another 1gb droplet, And i get same error but more often, some traffic but not much

-Custom theme
-some plug ins
-w3 cache
-I have swap
-iredmail installed

@kamal or anybody that has a solution ?
After power cycle all database connect error,restore the backup also can not to solve it?
Looks like MySQL is crashing/running out of memory. If you've already added swap, you might need to upgrade your droplet to get more memory or you could try optimizing MySQL's configs to use less memory.

Please change it to mariadb. Mysql leaking memory.

I have an 80GB droplet with a quad-core processor and still have these issues. I suspect it may relate to some plugin, but to isolate that across about 12 domains is just too much.

So for the time being I restart Apache every 10 minutes and MySQL every 30 minutes from a cron job.

Thinking about installing nagios to monitor the droplet but it’s a lot of work to configure nagios.

i have smae as problem ,this is my site Example link is alway …

wow it’s 2015. I’m having the same exact problem. Brand new wordpress was working just a few days ago and now it’s completely down with this error message.

It’s ridiculous to believe that a simple wordpress site with no traffic would cause the server to run out of memory.

The whole point of using DO is for speed and now it can’t even handle a simple wordpress site.

It took hours to figure out how to get up and running with DO and now I’m back to square one.

I have to go to WPengine instead.

What a headache.

Yea 2015 this is bad I have swap enabled and the same thing is happening. I am thinking A Small Orange Tree as a host.

Here is the same on
We need to restart mySQL at least one time a day.
Please help!

I have 1 gb memory still have same problem

We need a more friendly company for this type of hosting. I know one is in the work in due time. This is system wide and annoying.

  • Same problem, Google webmaster tools always has to notify me that the server is down. I upgraded the server. I did a memory swap. No idea what to do. Seems like this is common enough that DO should address it

I was running into a similar issue. Upon reboot the /var/run/mysqld directory seemed to vanish. See for more detail.

same here on a brand new fedora 23 wp installation with mariadb. Runs just a few hours. Only “solution” for me was crontab restarts

Same here, it’s really frustrating and costly to pay programmers if they cannot find a solution but blame it on the hosting by DigitalOcean. Please comment on this, DigitalOcean.

I’ll just add to the chorus that I’m having the same issue. Sounds exactly like what the rest of you are experiencing. Fortunately a quick reboot fixes things, but it seems to be cropping up more often lately.

Same issue still happening in 2016!! I am going to host Wordpress site not in DO anymore

Same problem on my end - I’ve got a Vanilla Wordpress install with a few plugins, almost no content and no visitors. The site crashes every few days with a MySQL database error.

This is on a 1gb memory Droplet using the Wordpress 1-click install on far everything I’ve heard from support is that it’s on my end and I have to fix it.

Same problem here as well, going to setup crontab restarts, as I cannot handle it anymore.

Problem solve with this code.. Very simple :)

sudo start mysql

same problem here.
Every day, some days more that once “error establishing a database connection ”

Yup: I have been having this exact same problem lately. A site that is hardly in use and not public (never been indexed by search engines) and only ever accessed by 2 people.

Lately, it has been so frequent it is a joke. I have run droplets with 512 MBs before with WordPress with no issues. This is the first time that i see this.

DO should address this issue or offer a solution as so many people have already reported before.

Submit an Answer