Increase site speed for wordpress site and eliminate error establishing connection to database

December 22, 2014 2.5k views

I have a 10gb droplet running a wordpress site. I’ve always had the ‘error establishing connection to database’ error, which I discovered came from mysql crashing (no idea why). Every time it happens I have to restart mysql and the site comes back online. I figured it was due to low memory and followed the swap file tutorial – still have the problem.

Additionally, the site has significantly increased in traffic (10x growth in the past week) but still under 5k visits a day. This has resulted in site slowdowns and a higher frequency of the database error (up to 5 times a day, unbelievably frustrating) Should I upgrade my droplet to a larger size? How can I increase site speeds and eliminate the database error (all login credentials in wp-config are correct).

2 comments
2 Answers

Would you mind providing a link to your wordpress site ?
You could try installing mysqltuner to optimize your mysql settings.

Hi there,

it’s an error establishing a database connection. Here’s what it means exactly:

WordPress uses two main pieces of technology to provide you with all its awesome abilities: PHP and MySQL.

PHP is a programming language. WordPress – the core WordPress files – have been written in PHP. Boring, sorry.
MySQL is a database technology. WordPress uses a MySQL database to store all of your website’s content. This includes your posts, pages, but also the smaller elements, such as the title of your site, the layout of your widgets, the color settings, and etc. Basically, the MySQL database is where every, even the smallest piece of information about your website, is kept.

Putting the two together, WordPress uses PHP commands to connect to the MySQL database, get the information it needs, and then displays everything on the screen.

This is where the error comes into play. The error occurs when, for whatever reason, WordPress cannot access the information in the database via PHP commands. When that happens, WordPress basically doesn’t know what to do next, so the only thing it can say is, “Error establishing a database connection.”

With that being said, there can be a handful of reasons why the error occurs. Some of the more common ones:

  1. Incorrect login credentials. WordPress needs a specific login and password to access the database. If those have changed for any reason then WordPress will no longer be able to fetch anything from the database.

  2. Corrupted WordPress files. The core WordPress files can get corrupted as a result of a failed update, among others. This can include things like failed updates of the plugins, themes, and even the main WordPress software updates.

  3. Corrupted database. This might be a result of a rogue plugin messing up the database internally, a hacker’s attack, a theme failing, and many more.

  4. The database server is down. In some cases, the web server – the server that stores your website files – is run on a different machine than the database. And that separate database server can simply be down for whatever reason.

  5. Too much traffic. Even though this is a good problem to have, it’s still a problem. Specifically, your database might be unresponsive due to a high spike in traffic. For example, maybe one of your posts went viral and now everyone and their dog tries to access your site? Hence the server is not able to handle part of those visits.

edited by MattIPv4
Have another answer? Share your knowledge.

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