RedWaterHST
← All answers

Fixing “Error establishing a database connection” in WordPress

This error means one thing: WordPress asked the database for your content and got no answer. The site's files are fine. The question is why the database didn't pick up, and the causes below cover nearly every case, in order of likelihood.

1. Wrong credentials in wp-config.php

By far the most common cause right after a migration or a manual edit. WordPress reads four values from wp-config.php: database name, username, password, and host. If any one of them is stale, you get this exact error. Compare them against the database that actually exists in your hosting control panel. Watch for the database host too. Some hosts use localhost, others use a server address.

2. The database server hiccuped

If the site worked an hour ago and nobody touched anything, the database service may have restarted or run out of memory. On our hosting you don't need to diagnose this yourself. Open a ticket and we'll check the server side; that's our job, not yours.

3. Corrupted tables

Rare, but it happens after a crash mid-write. WordPress ships a repair tool. Add this line to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Then visit yourdomain.com/wp-admin/maint/repair.php and run the repair. Remove the line afterwards, since that page needs no login while the flag is on.

4. The database doesn't exist

Restores and migrations sometimes create the user but not the database, or the other way round. Check your control panel for both, and confirm the user is actually assigned to the database with full privileges.

If you're hosting with us

Skip the checklist and open a ticket with the words "database connection error." An engineer looks at the actual server logs, which beats guessing from the outside every time. This is included on every plan, not a paid extra.

Still stuck?

Open a ticket and a real engineer will sort it out with you.