Is this your problem?
- Every page shows "Error establishing a database connection"
- wp-admin says "One or more database tables are unavailable"
- It started after moving the site, or changing a hosting password
- The site comes and goes during busy times
What usually causes it
How to tell: It started after a move, a restore, or a password change in the host panel.
How to tell: Other sites on the same host fail too, or the host status page shows an incident. It often comes and goes.
How to tell: wp-admin shows a different message about tables that need to be repaired.
How to tell: The disk is full, or the host throttles the account during traffic spikes.
Before you touch anything
- Download a copy of wp-config.php before you edit it.
- If the host panel offers a database backup, take one.
How to fix it, step by step
-
1
Check whether it is the host
Look at your host status page and try another site on the same account. If the host is having an outage, there is nothing to fix on your side. Wait, and ask them for a time.
-
2
Compare wp-config.php with the host panel
Open wp-config.php and find these four lines. Check each value against the database and user listed in your host panel, usually under MySQL Databases. DB_HOST is often localhost, but some hosts use their own address.
define( "DB_NAME", "database_name" ); define( "DB_USER", "database_user" ); define( "DB_PASSWORD", "password" ); define( "DB_HOST", "localhost" ); -
3
Reset the database password if unsure
In the host panel, set a new password for the database user, make sure that user is attached to the database with all privileges, and put the new password in wp-config.php.
-
4
Repair damaged tables
Add this line to wp-config.php, then visit yoursite.com/wp-admin/maint/repair.php and choose Repair Database. Remove the line straight after: while it is there, anyone can open that page.
define( "WP_ALLOW_REPAIR", true ); -
5
Check the disk and limits
In the host panel, check disk usage and resource limits. A full disk stops the database writing. Clear old backups or logs, or ask the host to raise the limit.
Stop and get help if
- The database is missing from the host panel altogether.
- You see tables with names you do not recognise, or an admin user you did not create.
- The only way back is restoring a backup, and the site takes orders or bookings.
Stop it happening again
- Keep a record of database details somewhere safe when you move a site.
- Watch uptime so you hear about outages before customers do.
- Choose hosting sized for your traffic, not the cheapest plan.
Questions people ask
Is my content gone?
Almost never. The site cannot reach the database, but the database is usually intact.
Why does it only happen sometimes?
That points to the database server being overloaded, often on shared hosting during busy periods.
Can a hack cause this?
It can, when an attacker changes the database password. Check for unfamiliar admin users once the site is back.