Skip to content

How to Fix “Error Establishing a Database Connection” in WordPress

Fix the WordPress “Error establishing a database connection”: check wp-config.php credentials, the database server, user permissions and corrupted tables.
How to Fix “Error Establishing a Database Connection” in WordPress — WebDesigningPune guide
Quick answer

“Error establishing a database connection” means WordPress cannot reach its MySQL/MariaDB database. The usual causes are wrong database details in wp-config.php, the database server being down or overloaded, a database user without permissions, or corrupted tables. Check the credentials first, then ask your host whether the database server is running, and repair the database if needed.

Few WordPress messages cause as much panic as a blank white page with the words “Error establishing a database connection”. It looks like everything is gone. In almost every case, it is not — your posts, pages and settings are still in the database. WordPress simply cannot reach it at the moment.

Work through the checks below calmly and in order. Most sites are back online within minutes.

This error stops the whole site because WordPress stores everything in its database. Work through the checks below.

Important: Before changing files or the database, take a backup if you can. If you cannot log in, your host’s backups or file manager can help — see how to back up WordPress.

1. Check the database details in wp-config.php

Open wp-config.php in your site’s root folder and compare these values with the database details in your hosting panel:

Error establishing a database connection: check the database details in wp-config.php
define( 'DB_NAME', 'database_name' );     // exact database name
define( 'DB_USER', 'database_user' );     // user assigned to that database
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'localhost' );         // some hosts use a different hostname or port

After moving hosts or changing passwords, these are the most likely culprits. If you changed the database password in the hosting panel, update it here too.

2. Check the database server

If credentials are correct, the database server may be down or overloaded — common on busy shared hosting or during traffic spikes. Check your host’s status page or contact support. If other sites on the same account also fail, it is almost certainly a server issue.

3. Check user permissions

In your hosting panel’s database section, make sure the database user is assigned to the database with all privileges.

Screenshot or photo that supports “Check user permissions” in a guide about wordpress database error

4. Repair the database

If the front end shows the error but wp-admin says tables need repair, temporarily add this line to wp-config.php and visit /wp-admin/maint/repair.php:

define( 'WP_ALLOW_REPAIR', true ); // remove this line after repairing

Warning: The repair page does not require a login, so remove WP_ALLOW_REPAIR from wp-config.php as soon as you have finished.

5. Restore from backup

If the database is badly corrupted or was deleted, restore the most recent database backup from your host or backup plugin.

Prevent it from happening again

  • Use hosting with enough database resources for your traffic.
  • Enable page caching to reduce database load.
  • Keep regular database backups.
  • Clean up revisions, spam and expired transients.
Clean illustration for “Prevent it from happening again” (topic: wordpress database error)

For a complete method, see our WordPress troubleshooting guide.

Error establishing a database connection: quick triage

Situation Most likely cause Start with
Just moved hosts or changed passwords Wrong details in wp-config.php Step 1
Error appears and disappears Database server overloaded Contact your host; check traffic spikes
Only the admin area shows the error Corrupted database tables Repair the database
Several sites on the same host are down Host-wide database outage Check the host’s status page

What to tell your host’s support team

  • The exact error message and when it started.
  • Any recent changes (migration, updates, password changes).
  • Whether the error is constant or intermittent.
  • Whether other sites on the account are affected.
  • That you have checked wp-config.php details.

Tip: After fixing the problem, set up uptime monitoring. You will get an alert within minutes if the site goes down again, instead of hearing from a customer.


Frequently asked questions

What causes the error establishing a database connection?

Incorrect database credentials in wp-config.php, a database server that is down or overloaded, missing user permissions, or corrupted database tables.

Is my website data lost?

Usually not. The data is still in the database; WordPress just cannot connect to it. Fixing the connection restores the site.

Why does the error appear only sometimes?

Intermittent errors usually mean the database server is overloaded by traffic or limited resources. Caching and better hosting help.

Can a plugin cause a database connection error?

Rarely directly, but plugins that run heavy queries can overload a small database server and contribute to the problem.

Can I fix the database error without technical skills?

Often yes, with your host’s help. Checking wp-config.php details and contacting support resolves many cases.

Will reinstalling WordPress fix the database error?

Usually not, because the problem is the database connection, not WordPress files. Check credentials and the database server first.

Could my site have been hacked?

It is possible but uncommon. If credentials changed unexpectedly or you see unknown files, run a security scan and contact your host.


Further reading: the official WordPress documentation.

First published November 17, 2026 · Last updated November 26, 2026