Question

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

  • Posted September 4, 2013

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.

Subscribe
Share

Go here: http://www.thegeekstuff.com/2010/08/how-to-add-swap-space/

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

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 serverpilot.io to manage my WP install. I’ve followed their suggested settings. https://serverpilot.io/community/articles/how-to-install-wp-super-cache.html

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

It also seems swap is enabled.

Running sudo swapon -s returns the following:

/swapfile                               file		524284	0	-1

Any ideas?

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


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Hi Everyone, please I need help: <br> <br>When i try to access myipaddress/phpmyadmin i get the following error: <br> <br>phpMyAdmin - Error <br>The mysqli extension is missing. Please check your PHP configuration. <a href=“Documentation.html#faqmysql” target=“documentation”><img class=“icon” src=“./themes/pmahomme/img/b_help.png” width=“11” height=“11” alt=“Documentation” title=“Documentation” /></a> <br> <br>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. <br> <br>Please help, very urgent.

@Dave: Is MySQL running? <code>sudo service mysql status</code> <br> <br>Was it working fine previously?

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.

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

Problem solve with this code… Very simple :)

sudo start mysql

Same problem here as well, going to setup crontab restarts, as I cannot handle it 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 Ubuntu…so far everything I’ve heard from support is that it’s on my end and I have to fix it.

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

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 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.