Seeing “Error establishing a database connection” instead of your WordPress site is alarming, but it’s one of the most common WordPress errors and almost always fixable without losing any data. This guide walks through exactly what causes it and how to fix it, step by step.
What This Error Means
WordPress stores all your posts, pages, settings and user data in a MySQL (or MariaDB) database. Every time someone visits your site, WordPress connects to that database to pull the content. This error simply means WordPress tried to connect and failed — it says nothing about why on its own, which is why troubleshooting it means checking a short list of usual suspects in order.
Common Causes
- Incorrect database credentials in
wp-config.php(often after a site migration or a host changing something) - A corrupted database table
- The database server being down or overloaded
- An incorrect database host value (common with some managed hosts)
- A plugin or theme update that corrupted data
Step-by-Step Fix
1. Check Your Database Credentials in wp-config.php
Connect to your site via FTP or your host’s File Manager and open wp-config.php in the root folder. Confirm these four lines match what’s actually in your hosting control panel:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_username' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );
If any of these don’t match your hosting panel’s database details exactly, update them and save the file. This single step resolves the error in the majority of cases, especially after moving to new hosting.
2. Confirm the Database User Has Permissions
In your hosting control panel (cPanel, hPanel, Plesk, etc.), check that the database user is actually assigned to that database with “All Privileges.” A user can exist and the password can be correct, but if it isn’t linked to the right database, you’ll see the same error.
3. Check If Your Database Server Is Down
Shared hosting occasionally has database server outages, especially during traffic spikes. Contact your host and ask directly: “Is the MySQL server for my account currently up?” This takes the guesswork out and is often the actual cause on budget hosting plans.
4. Repair the Database
If credentials are correct and the server is up, the database itself may have a corrupted table. Add this line to wp-config.php:
define( 'WP_ALLOW_REPAIR', true );
Then visit yoursite.com/wp-admin/maint/repair.php and click “Repair Database.” Once it finishes, remove that line from wp-config.php again — leaving it in place lets anyone who finds that URL run repairs on your site.
5. Rule Out a Theme or Plugin Conflict
If the error started right after installing or updating a plugin, rename that plugin’s folder via FTP (inside wp-content/plugins/) to deactivate it without needing admin access. If the site comes back, you’ve found the culprit.
When to Contact Your Host
If you’ve confirmed the credentials are correct and the database user has full privileges, and the error persists, this is a server-side issue your hosting provider needs to check directly — there’s nothing further to fix on the WordPress side.
Frequently Asked Questions
Will I lose my content fixing this?
No. This error is almost always a connection problem, not data loss. Your posts and pages remain in the database untouched while you fix the connection.
Does this only show on the homepage?
No — it typically appears on every page, including wp-admin, since every part of WordPress needs the database.
Related Guides

Written & Reviewed By
WordPress & SEO educator with 12+ years of experience, founder of Preet Web Vision, and creator of the Preet Tech Ideas YouTube channel.
