Few WordPress errors are as alarming as the dreaded “Error Establishing a Database Connection”. This message means your website can’t communicate with its database, leaving your site inaccessible to visitors and potentially harming your business. The good news? Most causes are straightforward to fix, even if you’re not a developer.
This guide will walk you through the essential steps to diagnose and resolve the issue, and help you know when it’s time to contact your hosting provider.
What Causes the Error?
WordPress relies on a database to store all your content, settings, and user information. If it can’t connect, you’ll see this error. The most common causes are:
- Incorrect database credentials (name, username, password, or host)
- Corrupted database tables
- Database server issues (such as downtime or overload)
- Corrupted WordPress core files
Let’s get your site back online.
1. Check Your Database Credentials
The most frequent cause is incorrect login details in your wp-config.php file. This often happens after a site migration or hosting change.
How to check:
-
Access your site files via cPanel File Manager or FTP.
-
Open the
wp-config.phpfile in your site’s root directory. -
Look for these lines:
php
Copydefine( ‘DB_NAME’, ‘your_database_name’ ); define( ‘DB_USER’, ‘your_database_user’ ); define( ‘DB_PASSWORD’, ‘your_database_password’ ); define( ‘DB_HOST’, ‘localhost’ ); -
Double-check these details against your hosting control panel (usually under “MySQL Databases” or similar). If you’re unsure, your host’s support can confirm the correct values.
Tip: Most UK hosts use localhost for DB_HOST, but some managed hosts use a different value.
2. Repair the WordPress Database
If your credentials are correct but you’re still seeing the error, your database may be corrupted. WordPress has a built-in repair tool.
How to repair:
-
In
wp-config.php, add this line just before “That’s all, stop editing!”:php
Copydefine(‘WP_ALLOW_REPAIR’, true); -
Visit:
http://yourdomain.com/wp-admin/maint/repair.php -
Click “Repair Database”. (You don’t need to be logged in.)
-
Once complete, remove the line you added to
wp-config.phpfor security.
Alternatively, many hosts allow you to repair the database from cPanel under “MySQL Databases”.
3. Check if the Database Server Is Down
If your credentials are correct and the database isn’t corrupted, the server itself may be down or overloaded—especially on shared hosting.
How to check:
- Try accessing phpMyAdmin from your hosting control panel. If it won’t load, the server may be down.
- If you have other sites on the same hosting, check if they’re also affected.
- Contact your hosting provider’s support and ask if there are any ongoing issues with the MySQL server.
4. Restore from a Backup
If you’ve recently made changes or updates and the error appeared, restoring a recent backup can be the quickest fix. Most reputable hosts offer one-click restore options in their control panel.
5. When to Contact Your Host
If you’ve checked your credentials, repaired the database, and confirmed the server is running but the error persists, it’s time to contact your hosting provider. Provide them with details of what you’ve tried—they’ll be able to check server logs and resolve deeper issues.
Prevention Tips
- Always keep a recent backup of your site and database.
- Avoid editing core files unless necessary.
- Use reputable plugins and themes.
- If you’re moving hosts, double-check all database settings.

Chris Barnard has spent over 15 years delivering exceptional revenue growth for ambitious businesses in the UK, Europe and North America through his marketing technology business, FeedbackFans.com and as an independent business consultant.
By his mid-20’s he was running digital departments for FTSE100 companies in London, eventually leading to a very successful period in digital customer acquisiton for a well-known brand in his early 30’s generating nine-figure revenues with seven-figure budgets. He now puts his experience, knowledge and ideas into good use, supporting challenger insurgent brands and forward thinking businesses to outperform in their sectors, whilst disrupting and improving the marketing, technology and development sectors.
Feedback Fans provides a unique next-generation managed technology and marketing platform that delivers outstanding and out-sized results for businesses in sectors such as finance, retail, leisure, and professional services.
With our unparalleled expertise in creating cutting-edge solutions and environments, we empower our clients and users to thrive and outperform in the digital age.
Chris Barnard is Managing Director of FeedbackFans.com and producer of the Bear Business Vodcast