Home » WordPress » Error Establishing a Database Connection: Check Credentials, Host and Server

Error Establishing a Database Connection: Check Credentials, Host and Server

Published 2026-10-03 | WordPress

Error Establishing a Database Connection: Check Credentials, Host and Server banner

Every page on a database-driven site starts with the same step: log in to the database and fetch the content. When that login fails, there is nothing to show. WordPress displays "Error establishing a database connection". Other systems show similar messages or a 500 error.

There are only a few possible reasons, and you can check each one.

Step 1: is it the whole site or just the front end?

Visit /wp-admin/. If it shows a different message, such as "One or more database tables are unavailable", the connection is working and some tables need repair (see the FAQ). If it shows the same error, the connection itself fails. Continue below.

Step 2: read the connection details

Open wp-config.php in the site root. Near the top you will find four values:

define('DB_NAME', 'site_wp');
define('DB_USER', 'site_wpuser');
define('DB_PASSWORD', '...');
define('DB_HOST', 'localhost');

Every one must match the real database exactly, including case and any account prefix your host adds (cPanel often uses accountname_dbname).

Step 3: compare with the control panel

In cPanel, open MySQL Databases. Check:

  • A database with the name in DB_NAME exists.
  • A user with the name in DB_USER exists.
  • That user is added to that database with all privileges. A user that exists but is not attached gives exactly this error.

You cannot read the old password, but you can set a new one for the user and paste it into DB_PASSWORD. That rules out a wrong password in one move.

Step 4: check the host value

localhost is correct for most shared hosts, but not all. Managed hosts and cloud databases often need a hostname such as mysql.example-host.com or an IP with a port (10.0.0.5:3306). The host's documentation or welcome email lists the right value. After a migration, this is frequently the one that changed.

Step 5: test the login directly

If you have SSH access, try the credentials outside WordPress:

mysql -u site_wpuser -p -h localhost site_wp
  • Access denied → username or password is wrong, or the user lacks rights to that database.
  • Can't connect to MySQL server → the server is down, the host value is wrong, or a firewall blocks the port.
  • A mysql> prompt → credentials are fine. Recheck wp-config.php for typos, stray spaces or curly quotes.

Step 6: is the database server running?

On your own server:

sudo systemctl status mysql

If it stopped, read why before restarting: sudo journalctl -u mysql -n 50. Running out of memory or disk space is common. A full disk prevents MySQL from starting at all.

On shared hosting, check the host's status page or ask support. Heavy traffic can also exhaust the allowed number of connections, causing the error only at busy times.

Common mistakes

  • Copying credentials from an old backup of wp-config.php after the host changed them.
  • Forgetting the account prefix on the database or user name.
  • Creating a new user but not attaching it to the database.
  • Restoring a site to a new host but keeping the old host's DB_HOST.

Frequently Asked Questions

Have I lost my content?

Almost certainly not. The message means the site cannot reach the database, not that the database is gone. Once the connection works, everything returns.

Why did it start without me changing anything?

The host may have changed the database password or server name during a migration, the database server may be overloaded or restarting, or your account may have hit a resource limit.

What does 'One or more database tables are unavailable' mean?

The connection worked but some tables are damaged. WordPress can repair them: add define('WP_ALLOW_REPAIR', true); to wp-config.php, visit /wp-admin/maint/repair.php, then remove the line.

Found a mistake or still stuck? Contact us. See how we write and check these guides in our editorial policy, or read about DocumentGuy.

More in WordPress