"Error establishing a database connection" means WordPress cannot reach the database that stores your posts, settings, and users, so no page can load. It is usually caused by wrong database login details in your wp-config.php file, or by the database server being down. Most cases are fixable in a few minutes.
wp-config.php, often after a migration or a manual edit./wp-admin/ says tables "may need to be repaired," you have corrupted database tables.wp-config.php — one typo can take the whole site offline.You open your website and instead of your homepage you see a plain white page with a single line: "Error establishing a database connection." The front end is gone. Often /wp-admin/ is unreachable too. There is no menu, no design, and no obvious reason it happened.
This is one of the most alarming WordPress errors because it takes down every page at once. The good news: your content is almost never lost. The error is about a broken connection, not deleted data. This guide is for site owners on shared, managed, or VPS hosting who want to find the cause and fix it safely. It is part of our guide to common server errors, which covers where this fits alongside other outages.
Before changing anything, run three quick checks. They point you straight at the cause and stop you editing files you don't need to touch.
Check 1 — Does /wp-admin/ show a different message? Visit yoursite.com/wp-admin/. If it loads a message like "One or more database tables are unavailable. The database may need to be repaired," your database is reachable but some tables (the structured storage inside the database) are corrupted. That is a repair job, not a credentials job.
Check 2 — Did you just change something? A recent migration, a host move, a password reset, or a manual edit to wp-config.php almost always means wrong credentials. The login details WordPress uses no longer match the database.
Check 3 — Can you open phpMyAdmin? phpMyAdmin is the database management tool in your hosting dashboard. If it opens and shows your tables, the database server is alive and the problem is on the WordPress side. If phpMyAdmin also fails or times out, the database server itself is down or overloaded — a host-side issue.
Is it your site or your host? Try to open phpMyAdmin from your hosting control panel. If phpMyAdmin loads normally, the database server is fine and the cause is in your site (usually credentials or corrupted tables) — you can fix it with the steps below. If phpMyAdmin also errors, times out, or refuses to connect, the database server is down or overloaded. That is your host's responsibility. Open a support ticket rather than editing your files.
WordPress stores almost everything — your posts, pages, comments, users, and settings — in a database, a separate program running alongside your files. That database is usually MySQL or MariaDB (a drop-in replacement for MySQL that most hosts now use). Your theme files and images live on disk; everything else lives in the database.
On every page load, WordPress opens a connection to the database using four settings stored in your wp-config.php file: DB_NAME (the database name), DB_USER (the username), DB_PASSWORD (the password), and DB_HOST (the address of the database server). If any of those is wrong, or the server on the other end does not answer, WordPress cannot read your content and shows the connection error.
So there are only two broad failure points: WordPress is asking the wrong way (bad credentials, wrong host, corrupted core files) or the database can't answer (server down, overloaded, or its tables are damaged). Everything below maps to one of those.
Five causes produce this one error. Match your symptom to the cause, then jump to the matching step.
| Likely cause | Tell-tale sign | Where to fix |
|---|---|---|
| Wrong database credentials | Started right after a migration or manual edit | Steps 2–3 |
Wrong DB_HOST value | Credentials look right but still fails; new host | Step 3 |
| Database server down / overloaded | phpMyAdmin also fails to open | Step 4 (contact host) |
| Corrupted database tables | /wp-admin/ mentions "repair" | Step 5 |
| Corrupted WordPress core files | Started after a failed update or upload | Step 6 |
| Exceeded resource / connection limits | Comes and goes under traffic; nothing else wrong | Step 8 |
Work through these in order. Stop as soon as your site loads again — you may not need every step.
wp-config.php.wp-config.php. Open wp-config.php in the site's root folder using your host's File Manager or an FTP client. Compare DB_NAME, DB_USER, and DB_PASSWORD against your host's database details, found in hPanel or cPanel under Databases / phpMyAdmin. Watch for typos, trailing spaces, and smart or "curly" quotes — each value must sit inside straight single quotes, like define('DB_NAME', 'my_database');.DB_HOST value. In the same file, confirm DB_HOST. On most shared hosts it is 'localhost', but some hosts require a specific hostname such as '127.0.0.1', a server name, or a port. Copy the exact value your host lists in its database settings and paste it in, for example define('DB_HOST', 'localhost');./wp-admin/ reported that tables need repairing, add this line to wp-config.php, just above the line that says "That's all, stop editing": define('WP_ALLOW_REPAIR', true);. Then visit yoursite.com/wp-admin/maint/repair.php, click "Repair Database," and let it finish. When it is done, remove that line from wp-config.php — leaving it in place is a security risk because the repair page needs no login.wp-admin and wp-includes folders over the existing ones via FTP. This overwrites damaged core files without touching your content, themes, or plugins in wp-content.Never edit wp-config.php without a backup, and never leave WP_ALLOW_REPAIR enabled. A single wrong character in wp-config.php takes the whole site down, and the repair page at /maint/repair.php requires no password — anyone who finds it can run it. Back up first, and delete the repair line the moment you are finished.
Beyond those two, the mistakes we see most often are:
DB_HOST. People assume it is always localhost and never check. On some hosts it is a specific server name, so the connection fails even with a correct username and password.wp-config.php before changing it so you can put the original back in seconds.You cannot stop every outage, but you can make this error rare and quick to recover from:
DB_HOST and database name recorded makes a future fix a two-minute job.It means WordPress tried to open its database — where your posts, pages, users, and settings are stored — and got no valid answer. Either the login details WordPress used are wrong, or the database server did not respond. Because every page needs the database, the whole site shows this one message until the connection works again.
Open phpMyAdmin from your hosting dashboard. If it loads and shows your tables, the database server is healthy and the cause is on your side — usually wrong credentials or corrupted tables you can fix. If phpMyAdmin also fails or times out, the database server itself is down or overloaded, which is your host's responsibility to resolve.
Your current credentials live in the wp-config.php file in your site's root folder, as DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. The correct values are shown in your hosting control panel — in hPanel or cPanel under the Databases or MySQL Databases section, and inside phpMyAdmin. Compare the two to spot a mismatch.
Yes, if you back up first. wp-config.php is a normal text file, but it is sensitive: one wrong character can take the site offline. Download a copy before you change anything so you can restore the original instantly, edit it in a plain-text editor to avoid smart quotes, and change only the lines you need to.
A sudden error with no edits on your part almost always points to the host: the database server crashed, was restarted, or was overloaded by other sites on a shared server. A traffic spike hitting your plan's connection limit can also cause it. Check phpMyAdmin — if it fails too, contact your host.
Almost never. The error is about a lost connection, not deleted data. Your posts and settings are still in the database. Once the connection is restored — by fixing credentials, repairing tables, or the host bringing the server back — your content reappears exactly as it was.
Usually not. Checking credentials, testing phpMyAdmin, and running the built-in repair tool are all things a careful site owner can do by following the steps above. If phpMyAdmin fails, the fix is simply to contact your host. Consider a developer only if core files are badly damaged and a backup restore is not possible.
"Error establishing a database connection" means WordPress and its database have lost contact, so the whole site goes blank — but your content is almost always safe. Start by opening phpMyAdmin to learn whether it's your site or your host. If phpMyAdmin works, check your credentials and DB_HOST in wp-config.php, repair corrupted tables, or restore a backup. If phpMyAdmin fails, the server is down and it's the host's job. If this is one of several errors you're seeing, our server errors guide is the next step to map the wider picture.
When the fix is a better-isolated host. If you have ruled out your own configuration — credentials are correct, phpMyAdmin works when the server is up, and the error keeps returning because the database server is repeatedly down or overloaded — the real cause is often an oversold shared plan, where too many sites compete for the same database resources. In that specific case, moving to a host with stronger resource isolation ends the recurring outages, because your database is no longer starved by your neighbours. Hostinger is one example worth comparing on that basis; look at the resource limits and isolation of each plan against your traffic. If valid at checkout, new users may be able to apply a code such as SPECIAL15 or SPECIAL10, subject to Hostinger's terms. If your own config was the problem and you've fixed it, you don't need to switch anything.
Affiliate disclosure: if you sign up through this link we may earn a commission, at no extra cost to you. How this works.
WP_ALLOW_REPAIR reference.REPAIR TABLE.The editorial team behind the Bitrich777 Hosting Help Center — practical, tested guides on web hosting, WordPress, servers, DNS, SSL, email, security and migration. Every walkthrough is reproduced on a live host before it is published.
View all guides by the Hosting Team Spotted an error? Tell us