You open your website and instead of your homepage, a stark message appears: “Error Establishing a Database Connection.” It looks terminal — and in a sense it is, because WordPress literally cannot load a single page without its database. But the cause is usually something simple: wrong database credentials after a move, a crashed database server, or a corrupted table. All fixable, and usually within half an hour.
This guide explains what the error means, walks through the fixes in order, and shows you how to check each possible cause without guessing.
Quick Answer
The “Error Establishing a Database Connection” message means WordPress can’t connect to its database. The most common causes are wrong database name, username, password, or host in wp-config.php; a database server that’s down (ask your host); or a corrupted database table. Fix it by checking the credentials in wp-config.php against your hosting panel, adding a repair line to wp-config.php and visiting the repair page, and contacting your host if the database server itself is down.
What This Error Actually Means
WordPress is split in two halves: files (the code) and a MySQL database (all your content — posts, pages, settings, users). Every page load requires the code to log in to the database and fetch the content. The error means that login failed or the database didn’t answer. WordPress deliberately shows a vague message because detailed database errors would be a security gift to attackers.
The four usual suspects:
- Wrong credentials in wp-config.php — especially after migrating hosts or changing a database password.
- Database server down or overloaded — a problem on your host’s side, common on cheap shared hosting under load.
- Corrupted database tables — often after a crash or a failed update.
- Wrong database host — most hosts use “localhost”, but some use a specific server address; a migration can leave the old value behind.
The WordPress project’s own common WordPress errors documentation lists this error among the classics and confirms the same causes, which is reassuring: this is a well-understood problem with standard fixes.
Fix 1: Check the Credentials in wp-config.php
- Open wp-config.php (in your main WordPress folder) using FTP or your host’s file manager.
- Find these four lines and note the values:
DB_NAME,DB_USER,DB_PASSWORD, andDB_HOST. - Now open your hosting control panel’s database section (often “MySQL Databases”) and compare: the database name and username must match exactly, character for character.
- If the password is in doubt, reset the database user’s password in the hosting panel, then paste the new password into wp-config.php exactly.
- Save and reload your site. A surprising number of these errors — especially after migrations — end right here.
Fix 2: Test Whether the Database Itself Answers
- In your hosting panel, open phpMyAdmin and try to open your database.
- If phpMyAdmin won’t load or the database won’t open, the problem is the database server itself — that’s your host’s job. Skip to Fix 4.
- If it opens fine, look at the tables list. Your content tables (wp_posts, wp_options, wp_users) should be there. If the database is empty or missing tables, you may be looking at the wrong database — re-check DB_NAME.
Fix 3: Repair the Database
WordPress has a built-in repair tool that’s disabled by default:
- Add this line to wp-config.php, just above “That’s all, stop editing!”:
define( 'WP_ALLOW_REPAIR', true ); - Visit yourdomain.com/wp-admin/maint/repair.php in your browser (you don’t need to be logged in — which is why step 4 matters).
- Click Repair Database (or “Repair and Optimize” — repair alone is fine).
- When it finishes, remove the line from wp-config.php immediately. While it exists, anyone who knows the URL can access the repair page.
- Reload your site — corrupted tables are a frequent cause, and this fixes them without touching your content.
Fix 4: Check Whether It’s Your Host
If credentials are right and the database won’t respond, the server is likely down, overloaded, or your account has hit a resource limit (too many simultaneous connections is common on cheap shared plans during traffic spikes).
- Check your host’s status page, if they have one.
- Contact support and say precisely: “My WordPress site shows ‘Error Establishing a Database Connection’. Credentials in wp-config.php are verified. Please check whether the MySQL server is running and whether my account is hitting connection limits.” This sentence saves three rounds of scripted replies.
- If this error recurs regularly at busy times, your site has outgrown the plan — more on that in the prevention section below.
Related but Different: The White Screen
Sometimes a database or plugin failure shows as a completely blank page instead of this message. The diagnosis path is similar but not identical — if you’re staring at emptiness rather than this error text, follow our guide on fixing the WordPress white screen of death, which covers plugin conflicts and memory limits.
How to Prevent This Error
- Back up regularly: If a database corrupts beyond repair, a recent backup is the difference between an hour of work and losing the site. Keep automatic off-site backups running.
- Don’t hand-edit credentials casually: If you change database passwords or migrate hosts, update wp-config.php in the same sitting and test immediately.
- Watch for recurrence: One occurrence after a migration is normal. Weekly occurrences mean an overloaded server — upgrade the plan or move hosts.
- Keep plugins lean: Badly behaved plugins that open excessive database connections can trigger connection limits on shared hosting.
- Use your host’s monitoring: Many panels show database and resource usage; a site creeping toward its limits warns you before it fails.
Did the Error Start Right After a Change? Work Backwards
Timing is your best clue. If this error appeared immediately after migrating hosts, the cause is almost certainly credentials or DB_HOST — the new server’s values differ from the old ones your wp-config.php still holds. If it appeared after you changed a database password in your hosting panel (perhaps during a security tidy-up), wp-config.php simply needs the new password. After a host maintenance window, suspect the server and check their status page first. And if nothing changed on your side at all, lean toward corruption or server load. Retracing the last change before the error turns a scary generic message into a short, targeted fix — which is why calmly asking “what changed last?” should be your first instinct for almost every WordPress fault.
Conclusion
“Error Establishing a Database Connection” means WordPress can’t reach the database that holds your entire site — but the fix is methodical: verify the four credentials in wp-config.php, test the database in phpMyAdmin, run WordPress’s built-in repair tool, and involve your host if the server itself is down. Work through the steps in order and most sites are back within the half hour. Then set up proper backups and keep an eye on resource limits, so if it ever returns, it’s a nuisance rather than a crisis.
Frequently Asked Questions
What causes “Error Establishing a Database Connection” in WordPress?
Usually one of four things: incorrect database credentials in wp-config.php, a down or overloaded database server at your host, corrupted database tables, or a wrong database host value — most often surfacing after a migration or password change.
Will this error delete my posts and pages?
No. Your content lives in the database; the error means WordPress can’t reach it, not that it’s gone. Once the connection works again, everything reappears. Only actual database corruption or deletion loses data — which is why backups matter.
How do I find my database name, username, and password?
The current values are in wp-config.php in your WordPress folder. The authoritative values live in your hosting control panel under MySQL Databases, where you can also reset the database user’s password.
Why does this error keep coming back on my site?
Recurring errors usually mean your hosting plan’s database connection or resource limits are too low for your traffic, or a plugin is abusing the database. Your host can confirm which limit you’re hitting; upgrading the plan or removing the plugin resolves it.
Can a plugin cause a database connection error?
Indirectly, yes — a plugin that opens excessive connections or corrupts a table can trigger it, and a security plugin that changes credentials can too. But the direct causes are credentials, corruption, or the server, so check those first.


Leave a Reply