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.
- 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.
- 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.
- If a migration changed the database user or password, update only the affected value and test the site again.
- 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.