Website support, maintenance and fixes for UK businessesCall 0208 088 8371info@websupportservices.co.uk

HomeWordPress errorsError establishing a database connection: how to fix it

Error establishing a database connection: how to fix it

This error means WordPress cannot connect to the database it needs to load your site. The cause may be incorrect database settings, a database service problem, exhausted hosting resources or damaged database tables.

The message you might see

Error establishing a database connection

Different wording, or a file path in the message? Paste it into our free error finder to see which plugin or theme it comes from.

What the database connection error means

WordPress stores posts, pages, settings and user data in a MySQL or MariaDB database. To load a normal page, WordPress reads the database name, database user, password and host from wp-config.php, then asks the database server for the required data. If that connection cannot be made, WordPress displays "Error establishing a database connection" instead of the site.

The message does not automatically mean the database is lost. A wrong password after a hosting migration can produce the same screen as a database server outage. Before changing anything, check whether the failure began after a move, credential change, server maintenance or control panel change.

Common causes of a WordPress database connection error

Incorrect values for DB_NAME, DB_USER, DB_PASSWORD or DB_HOST in wp-config.php are a primary cause, especially after migrations or hosting changes. The database user can also exist but no longer have permission to access the WordPress database.

The database service itself may be unavailable, overloaded or stopped. Some hosting accounts can also hit database, storage or resource limits. If the error appears and disappears without any file changes, a server side issue becomes more likely.

Corrupted database tables are a separate possibility. WordPress may show a more specific message in the admin area when tables need repair. Do not assume corruption from the connection error alone, and do not run repair tools until you have a current backup.

How to fix the error establishing a database connection

Before editing files or the database, take a full backup of both website files and the database. If the host cannot create a fresh database backup because the service is down, preserve any recent verified backup before making changes.

  1. Check your hosting status and control panel first. Confirm that the database service is running and that the account has not hit a storage or database limit.
  2. Open wp-config.php and compare the database values with the database details shown by your host. Check the values carefully rather than replacing them from memory.
  3. If a migration changed the database user or password, update only the affected value and test the site again.
  4. If WordPress specifically reports damaged tables, you can use its repair facility. Add the following temporarily to wp-config.php:
define( 'WP_ALLOW_REPAIR', true );

Then visit /wp-admin/maint/repair.php and run the repair. Remove the line immediately afterwards because the repair page does not require a logged in user while enabled. If repair fails, restore from a known good backup or ask the host or a developer to inspect the database rather than repeatedly modifying tables.

When to stop and get help with a database error

Stop if you are unsure which database belongs to the site, the connection details appear correct but the server still refuses connections, a repair reports missing or unrecoverable tables, or you do not have a reliable backup. Database changes can affect the whole site, so trial and error in phpMyAdmin is not a safe troubleshooting method.

Web Support Services offers an Emergency Fix for £249 per incident, with a response within 2 working hours. For ongoing updates, backups and monitoring, care plans start from £59 a month.

Common questions

Answers to the questions we hear most about this.

Does this error mean my WordPress database has been deleted?

No. The same message can be caused by incorrect credentials, a stopped database service, permissions or resource limits. Check the connection details and hosting status before assuming data is missing.

Where are the WordPress database login details stored?

They are normally defined in wp-config.php using DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.

Is the WordPress database repair tool safe to leave enabled?

No. Enable WP_ALLOW_REPAIR only when it is needed, run the repair, then remove the line from wp-config.php because the repair page can be accessed without logging in while it is enabled.

Site down or showing an error?

Call us now. Emergency Fix is £149 with a response within 2 working hours, and no fix means no fee.

Get website support