Your website has been replaced by one plain line of text, Error establishing a database connection. There’s no design, no menu and no way into the dashboard. If this is a business site, your stomach has probably dropped, and the first question in your head is whether everything is gone.
Almost certainly not. This error means WordPress can’t reach your database right now. It doesn’t mean the database has been wiped. Your posts, pages, orders and customers are very likely sitting exactly where they were, waiting for the connection to come back.

I’ll take you through this in the order I’d do it on a client’s site, starting with the checks that can’t make anything worse.
Before you touch anything
When a site goes down, the urge is to do something quickly. A few of the obvious moves can turn a ten minute problem into a real loss, so please hold off on these.
- Don’t restore a backup yet. If the cause is a wrong password or a host outage, a restore fixes nothing and can overwrite recent orders and form entries.
- Don’t reinstall WordPress. Your content isn’t in those files, so it won’t help.
- Don’t change the database password during a suspected host outage. You’d be adding a second problem to the first.
- Do download a copy of
wp-config.phpbefore you edit it, so you can always put it back.
Work out which problem you have
There are really only a handful of causes. WordPress’s own troubleshooting docs point first at the details in wp-config.php, and after that it’s usually the database server or damaged tables. These four questions will normally get you to the right one.

What happened just before the error is often your best clue. If you moved hosts or changed a password this morning, start with the login details. If nothing changed and the site was fine an hour ago, I’d suspect the server.
Is the database server actually running?
This takes two minutes and could save you an hour of editing files for nothing.
- Check your host’s status page or open a support chat.
- If you have other sites on the same account, see whether they’re down too. If they all are, it’s almost certainly the server.
- Try opening phpMyAdmin or the database tool in your hosting panel. If it can’t connect either, the database service itself is the problem.
If the server is down, your job is to report it rather than fix it. Tell your host your domain and the exact time the error started, then wait for them. It’s frustrating, but it’s also the outcome where you have nothing to repair.
Check the login details in wp-config.php
This is the most common cause after a migration, a host change, or someone tidying up the hosting panel. Open wp-config.php in your file manager or over SFTP. It’s in the main folder of your site, and these are the lines that matter.

Compare each one with your hosting panel. These are the mistakes I run into again and again.
- Someone changed the database password in the panel and never updated
wp-config.php. - The user exists but was never added to the database. In cPanel that’s a separate step, and it’s easy to miss after a migration.
- The new host adds an account prefix to database names, so
wpdbhas becomeaccount_wpdb. - The password contains a single quote, which breaks the line of PHP. Choose a strong password without quotes.
- The
$table_prefixline sayswp_while the tables in phpMyAdmin start with something else. This one usually opens the WordPress install screen instead of the database error, so if you see that screen after a move, fix this line and don’t run the installer.
The fastest proof is to log in to phpMyAdmin using the exact username and password from the file. If that fails, you’ve found your problem. Reset the password in your panel, paste the new one into wp-config.php, save, and reload your site.
Let a small script tell you exactly what’s wrong
WordPress hides the real reason behind its generic message. The database itself gives a much more useful answer, and this tiny file will show it to you. Save it as db-test.php next to wp-config.php, fill in your four values, and open yourdomain.com/db-test.php.
<?php
mysqli_report( MYSQLI_REPORT_OFF );
$link = @mysqli_connect( 'localhost', 'db_user', 'db_password', 'db_name' );
echo $link ? 'Connected. These details work.' : mysqli_connect_errno() . ' ' . mysqli_connect_error();Please delete this file the moment you have your answer, because it contains your database password. Then match the number you got. These codes come from the MySQL server and client error references, and MariaDB uses the same main ones.
| Code | What it means for you |
|---|---|
| 1045 | Access denied. The user or password is wrong, or the user has no access to this database. |
| 1049 | Unknown database. Check DB_NAME and any account prefix. |
| 2002 | Can’t connect. MySQL may be stopped, or DB_HOST or the port is wrong. With this PHP script, a refused connection and a misspelled host both show this code, so read the words after the number. |
| 2003 | Can’t reach the server. The mysql command line tool reports a refused or blocked connection this way. Check the host and port, or ask your host. |
| 2005 | Unknown host. The mysql command line tool uses this code when DB_HOST is misspelled or doesn’t exist. |
| 1040 | Too many connections. Your details are fine and the database is overloaded. |
When DB_HOST is the problem
Most hosts use localhost, but managed hosts and cloud databases often give you a specific address, sometimes with a port like db.example.com:3307. Your hosting panel or welcome email will have it.
There’s one small trick worth knowing. On Linux, MySQL treats localhost specially and connects through a socket file instead of the network. So if you get error 2002 with localhost, try 127.0.0.1. If that suddenly works, the socket path was the issue, and your host can tell you the right setting.
Repair damaged database tables
If the details are right and the server is up, a corrupted table is the next suspect. A helpful sign is your dashboard showing One or more database tables are unavailable. The database may need to be repaired.
Take a backup first, even of a database you think is broken. Then use the repair tool built into WordPress.
- Add this line to
wp-config.php, above the comment that says to stop editing.
define( 'WP_ALLOW_REPAIR', true );- Visit
yourdomain.com/wp-admin/maint/repair.php. - Click Repair Database. You can skip the optimize option, which takes longer and isn’t needed for the fix.
- Remove that line as soon as you’re done.
That last step really matters. As WordPress’s documentation explains, the repair page doesn’t need a login, because people with a broken database often can’t log in. Leave the line in place and anyone on the internet can run it.
If you have SSH access, WP-CLI does the same job and lets you take that backup in one go.
wp db export before-repair.sql
wp db check
wp db repairIf repair fails on core tables, that’s the point where restoring your most recent clean backup becomes the sensible choice.
When the error comes and goes
An error that shows up for a few minutes and then clears by itself is a different problem altogether. Your details are fine. The database is simply being asked to do more than it can, and it’s turning new connections away. You’ll often find error 1040 in your logs.
The usual reasons are a traffic spike, aggressive bots hitting uncached pages, a slow plugin such as a search, related posts or reporting tool, or a bloated wp_options table. Shared hosting limits play a part too, once a site has outgrown them.
If you can run SQL in phpMyAdmin, these three queries show how close you are to the limit.
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';
SHOW STATUS LIKE 'Max_used_connections';If the highest number used is at or near the maximum, you’ve confirmed it. Raising the limit only hides the problem, so I’d work on reducing the load. Turn on page caching, block bad bots at Cloudflare or your firewall, replace the slow plugin, and clean up autoloaded options. My WordPress performance audit guide shows how to find what’s using the most, and sometimes the honest answer is that the site needs better hosting.
Seeing this on your own computer?
If you’re on XAMPP, MAMP or LocalWP rather than a live site, the cause is usually much simpler.
- MySQL isn’t running. Start it in the XAMPP or MAMP control panel. In LocalWP, the database only runs while the site is started in the app.
- MySQL won’t start because another program is using port 3306. Stop that service, or change the port and add it to the host, as in
define( 'DB_HOST', 'localhost:3307' );. - Fresh XAMPP installs usually use the user
rootwith an empty password. If you’ve set a password in phpMyAdmin,wp-config.phpneeds it too. - After copying a site to your computer, the database may not exist yet. Create it in phpMyAdmin and import your SQL file first.
If the details changed and nobody changed them
This is rare, but don’t ignore it. If your database settings are different and no one on your side touched them, your site may have been compromised. Look for admin users you don’t recognize and recently modified files, and read about WordPress malware removal before you restore anything, or you could bring the infection straight back.
Make sure you’re not caught out next time
A few small habits make this error far less painful if it ever comes back.
- Set up uptime monitoring, so you hear about an outage before a customer tells you.
- Keep automatic daily backups stored away from your web server.
- Use page caching, so a traffic spike doesn’t reach your database.
- After any migration, test the site, a form and the login before you cancel the old hosting.
- Keep your database details in a password manager rather than an old email.
Questions people ask about this error
Have I lost my website content?
Very unlikely. To see for yourself, open phpMyAdmin and browse the wp_posts table, or the posts table with your own prefix. If your articles are listed there, your content is still in the database.
What causes the error establishing a database connection?
WordPress prints this one message for several different faults, so the wording alone can’t tell you the cause. It can be wrong details in wp-config.php, a stopped or overloaded database server, or damaged tables, and the error code from the test script above helps separate them.
Why does the error only appear at busy times?
Each uncached page load opens its own database connection and holds it until the page is built. When slow queries keep those connections open, new visitors can hit the connection limit and get this error.
Should I just restore a backup?
Not at first. Save it for damaged tables that repair couldn’t fix, and export the current database before you restore, so you keep a copy of anything newer than the backup.
Why does wp-admin show the same error?
The dashboard needs the database just as much as your public pages do. That’s why you can’t log in to fix it and have to work through your hosting panel or SSH instead.
Can a plugin cause this error?
Indirectly, yes. A plugin won’t normally change your login details, but a heavy one can keep database connections busy for too long. If the trouble began right after you installed or updated one, test that plugin first.
How long does it take to fix?
Wrong credentials take a few minutes once you’ve found them. A host outage depends on your host. Corrupted tables or an overloaded server can take longer, and that’s when a backup matters most.
If your site is down and you’d rather hand this over, I can find the cause and fix it with a backup taken first. Get a free website review, or read more about my WordPress error fixes.
You may also need my guides on the WordPress critical error and the white screen of death.





