Skip to content
The site is down

“Error establishing a database connection”

WordPress can't reach its database. The fault is in the login details in wp-config.php, the database server or the database itself.

You need
Hosting panel
Updated

The message means WordPress can't connect to its MySQL or MariaDB database, and without the database it can't build any pages. The problem is in the login details in wp-config.php, the database server or the database itself.

Check whether the database is corrupted

Open /wp-admin on your site. If it says "One or more database tables are unavailable", the database is corrupted and you can skip to the repair.

If wp-admin shows the same error as the front page, the connection itself is failing. The error happens before WordPress loads plugins and themes, so deactivating them won't help.

Check the login details in wp-config.php

If the site was recently moved, or someone changed the database password, wp-config.php has to be updated with the new details.

  1. Connect with FTP or the file manager in your hosting panel, and make a copy of wp-config.php in the WordPress root folder.
  2. Open the file and find these four lines:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'username' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
  1. Compare the values with the database details in your hosting panel. With many providers the host name is something other than localhost.
  2. Correct the values, save the file and reload the site.

Change only the values between the single quotes. One missing quote in wp-config.php breaks the whole site.

If the page says "Cannot select database" instead, the username and password are correct, but the database in DB_NAME doesn't exist or the user has no access to it.

Check whether the database server responds

If the login details are correct, the database server may be down or overloaded. A typical sign is that the error comes and goes, or that it shows up when traffic increases.

Look for service notices in your hosting panel, and try to open the database in phpMyAdmin. If that fails too, the problem is with your hosting provider, and they have to fix it.

On your own server, check that the database service is running with systemctl status mysql or systemctl status mariadb, and that the disk isn't full with df -h.

Repair the database

If wp-admin says the tables need repairing, WordPress has a tool for it. Export the database in phpMyAdmin first if you can, because a repair can cause data loss:

  1. Add this line to wp-config.php, just above the line with require_once ABSPATH . 'wp-settings.php';:
define( 'WP_ALLOW_REPAIR', true );
  1. Go to /wp-admin/maint/repair.php and click "Repair Database".
  2. Remove the line when the repair is done. While it's there, anyone can open the repair page without logging in.

When you're stuck

If the login details are correct, the database responds in phpMyAdmin and the repair doesn't help, the database user may have hit its connection limit or lost its permissions. That has to be checked in the hosting panel or by your hosting provider. If you don't have access to the hosting panel, find out who hosts the site first.