Spring Fresh Sale! - Up To 67% OFF BDIX Hosting + Free Domain
Troubleshooting

How to Fix “Error Establishing a Database Connection”

"Error establishing a database connection" means your website cannot talk to its database — so it cannot load any content. It looks scary, but the reasons are few: wrong login details, a database that is down or overloaded, or a corrupted table. Let us work through them.

Cause 1: Wrong database credentials

This is the most common cause, especially after moving a site or changing a password. Your site's config file must hold the correct database name, username, password and host. For WordPress that is wp-config.php; for other apps it is their own config. Confirm those details match a real database and user — see creating a MySQL database and user.

Cause 2: The database server is overloaded or down

If credentials are correct but the error is intermittent, the database may be struggling under load. Check your resource usage — a maxed-out account can drop database connections. Caching and optimisation reduce the pressure.

Cause 3: A corrupted database

Occasionally a table becomes corrupted. You can attempt a repair — see repairing a database via phpMyAdmin. WordPress also has a built-in repair mode you can enable in wp-config.php.

Step-by-step

  1. Open your config file and verify the database name, user, password and host.
  2. Confirm the user is assigned to that database with full privileges.
  3. Check resource usage for an overload.
  4. Repair the database if the first steps do not resolve it.

Frequently asked questions

It broke right after I migrated my site.

The credentials in your config almost certainly still point to the old database. Update the name, user, password and host to the new server's database. This fixes most post-migration cases.

The front end and wp-admin both fail — except wp-admin offers a repair.

If WordPress suggests a repair, a table is likely corrupted. Enable repair mode in wp-config.php, run it, then remove the line afterwards for security.

Credentials are right but it still fails sometimes.

Intermittent failures point to load or a resource limit, not credentials. Add caching, optimise the database, and check your usage graphs.

Was this article helpful?