First, the reassuring part

This error is a connection failure, not a data loss event. Your posts, pages, and orders are sitting on disk exactly where they were. Do not reinstall WordPress — that's how a recoverable outage turns into a real disaster.

Start here: two questions

Before changing anything, visit yoursite.com/wp-admin and compare it to the front page. The difference tells you which branch of the diagnosis you're on:

What wp-admin showsWhat it meansGo to
The same connection errorWordPress can't reach the server at allCredentials & server
"One or more database tables are unavailable… database may need to be repaired"Connection works; tables are corruptedTable repair

1. Verify the credentials

Open wp-config.php and find these four lines. Every one of them has to match what your host lists for the database:

define( 'DB_NAME', 'your_database' );
define( 'DB_USER', 'your_db_user' );
define( 'DB_PASSWORD', 'your_password' );
define( 'DB_HOST', 'localhost' );

The one that catches people is DB_HOST. localhost is correct on most shared hosting, but plenty of hosts require 127.0.0.1, a port (127.0.0.1:3306), or a dedicated hostname like mysql.yourhost.com. If your host recently migrated you to a new server, this is very often the single value that changed.

2. Test the connection outside WordPress

Don't guess whether the credentials work — prove it. Drop this file in your web root as dbtest.php, load it in a browser, then delete it immediately:

<?php
$c = @new mysqli('localhost', 'your_db_user', 'your_password', 'your_database');
echo $c->connect_error ? 'FAILED: ' . $c->connect_error : 'Connected fine.';

"Connected fine" means your credentials are correct and the problem is elsewhere — corrupted tables, a plugin holding connections open, or something injected into wp-config.php. Access denied means wrong username or password. Can't connect to MySQL server means the database service itself is unreachable.

3. Is the database server even running?

If the credentials test clean but WordPress still fails, the service is probably down or saturated. On shared hosting you can't restart it — but you can confirm it, and that changes who fixes it:

  • Other sites on the same account also down? Server-level problem. Contact your host; there's nothing to fix in your files.
  • Site works intermittently, fails under traffic? You're hitting max_connections. Common on shared hosting during a traffic spike — and often caused by one slow plugin query holding connections open.
  • Recently exceeded your plan's limits? Some hosts suspend the database before they suspend the account. Check your billing dashboard and your inbox.

4. Repair corrupted tables

If wp-admin told you the database needs repairing, add this to wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Then visit yoursite.com/wp-admin/maint/repair.php and run the repair. When it finishes, remove that line immediately — while it's present the repair page is accessible to anyone on the internet, without logging in.

Corruption is a symptom, not a cause

Tables don't corrupt themselves. An unexpected server reboot, a full disk, or a crashing MySQL process did it. If it happens twice, stop repairing and start asking your host why the service keeps dying.

5. When it's actually a compromise

A less obvious cause: malware that rewrote wp-config.php. Some infections modify the file and corrupt it in the process; others inject code above the opening <?php that breaks parsing. Open the file and check that it starts cleanly, has no unexpected eval() or base64 blocks, and that the credentials are the ones you recognise.

If your database password was changed and you didn't change it, treat this as a security incident, not a configuration problem.

Site still down?

Database outages are usually the fastest emergency to resolve — often inside 30 minutes. Send me the URL and your host name.

FAQ

What causes this error?

WordPress couldn't connect to MySQL. Four common causes: wrong credentials in wp-config.php, a database server that's down or overloaded, corrupted tables, and exhausted connection limits on shared hosting.

Why did it appear when I changed nothing?

Usually the host restarted or overloaded the database server, a shared-hosting connection limit was hit during a traffic spike, or the account was suspended. It can also follow an automatic password rotation by the host.

Will I lose my content?

Almost never. The data is still on disk — WordPress just can't reach it. Even genuine corruption is usually repairable. Don't reinstall WordPress.

It works sometimes and fails other times. Why?

Classic connection-limit exhaustion. Your database allows a fixed number of simultaneous connections, and under load you're hitting the ceiling. The real fix is finding the slow query or runaway plugin holding connections open.