Skink Insights - WordPress

What Does “Error Establishing a Database Connection” Mean in WordPress, and How Do You Fix It?

By

“Error establishing a database connection” means WordPress cannot talk to the database that holds your pages, posts and settings. It is usually caused by wrong login details in your configuration file, a database server that is down or overloaded, or a corrupted database. The good news is that it is almost always fixable, and your content is rarely lost.

Why does this error happen?

WordPress stores everything that makes your site yours in a MySQL or MariaDB database. Every time someone visits a page, WordPress asks the database for the content. If that request fails, visitors see a blank page with this one line of text.

The most common causes are:

  • The database name, username, password or host in your wp-config.php file no longer matches the hosting account, often after a migration or a password change.
  • The database server is down, overloaded or restarting, which is common on cheap shared hosting during traffic spikes.
  • One or more database tables have become corrupted.
  • Your hosting account has hit a resource limit or has been suspended.

Step 1: Check whether it is just a blip

Wait two or three minutes and refresh. If the error clears, the database server was briefly overloaded. Also try the login page at /wp-admin. If you see a different message there, such as “One or more database tables are unavailable”, you are dealing with corruption rather than a connection problem.

Step 2: Check your hosting status

Log in to your hosting control panel and look for any service notices. Confirm your account is active and not over its limits. If other sites on the same server are also down, the host needs to fix it, so contact their support straight away.

Step 3: Check your wp-config.php details

Using your host’s file manager or SFTP, open wp-config.php in the root folder of your site. Look for DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Compare them with the database details shown in your hosting panel. A single wrong character will cause the error. If you are unsure, reset the database user’s password in the panel and paste the new one into the file.

Take a copy of the file before you edit it, so you can put it back if something goes wrong.

Step 4: Repair the database

If the login details are correct, WordPress has a built-in repair tool. Add this line to wp-config.php, above the line that says “That’s all, stop editing”:

define( 'WP_ALLOW_REPAIR', true );

Then visit yoursite.com.au/wp-admin/maint/repair.php and choose “Repair Database”. Remove the line afterwards, because that page can be opened by anyone while it is active.

Step 5: Restore from a backup if needed

If repair does not work, restoring a recent backup is the safest route. This is why regular, tested backups matter so much. If you do not have one, ask your host whether they keep server-level copies. Many do, even when you have not set anything up yourself.

How do you stop it happening again?

Good hosting with enough resources for your traffic goes a long way, and so does keeping your site lean with regular housekeeping. If your site goes down repeatedly, the underlying cause is often hosting that has outgrown its plan, or a plugin hammering the database. Our WordPress development work includes tracking these problems down properly rather than patching the symptom, and you can find more practical guides in our insights.

Need a hand?

If your site is down right now and you would rather not edit configuration files yourself, call us on 02 9834 4119 or send us a message. We will get you back online and work out why it happened.

Rachael Orlando

Need a WordPress website, theme or plugin built properly? We would love to help.

Start a project