WordPress Debug Mode : “Error Establishing Database Connection”

database error

WordPress is one of the most popular open source content management systems in the world. Although it started out focused on blogging, over the years it has developed into a more flexible platform for websites in general. After almost fifteen years of development it is quite polished and robust, yet issues can still come up.

If you’ve recently attempted to load your WordPress-powered website and instead saw a message stating “Error Establishing Database Connection”, the cause is most often one of the following:

  • The database has crashed, often due to the server running out of memory
  • The database login credentials are incorrect in your WordPress configuration
  • The WordPress database tables have been damaged

Let’s walk through these issues one at a time to determine if they affect you, and how to fix them.

If you see one or more lines like the above, your MySQL server ran out of memory and quit. If it’s just one line, you may be temporarily experiencing unusual traffic. If there are many error lines, your server is regularly becoming memory constrained. Either way, the solution is to migrate to a server with more available memory. On most cloud providers it’s a simple matter to upgrade an existing server with minimal downtime.

If you see no output after running the zgrep command, your server is not running out of memory. If your site is still serving errors, continue on to the next step where we’ll look at our WordPress configuration and make sure the MySQL login details are correct.


This tutorial assumes the following:

  • You’re running WordPress on a machine that you have command line and sudo access to
  • Your database is running on the same server as WordPress (typical of a self-hosted WordPress setup, less typical of a shared WordPress hosting environment)
  • You know your database username, password, and the name of the database created for WordPress. This information should have been created during initial setup of your WordPress install.

Once the process finishes, be sure to open up the wp-config.php file again, and remove the line we just pasted in.

Did you notice any repairs being made? Try your site again, and check whether the error is gone. If unrepairable issues were found, you might need to restore the database from a backup if you have one available. Please reference our tutorial How To Import and Export Databases in MySQL for details on how to do so.

If no issues were found with the database, then we’ve still not discovered the problem. It could be intermittent issues we’re just missing, or something more obscure. Lets wrap up with a few other possibilities to try.

Tagged as: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *