Error Establishing a Database Connection
Fix the WordPress database connection error by checking wp-config.php, database credentials, MySQL/MariaDB health, and hosting changes.
Start here
Quick Answer
Check database credentials, DB host, database user privileges, MySQL or MariaDB service health, and table prefix first. In WordPress, compare DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, and $table_prefix in wp-config.php with the hosting control panel.
What this means in WordPress
This error means WordPress could not establish a connection to the configured database. The usual causes are wrong DB_NAME, DB_USER, DB_PASSWORD, or DB_HOST, a database server outage, missing user privileges, a migration mismatch, or connection limits on the host.
Safe credential checks
Compare wp-config.php with your hosting panel or deployment secrets. Do not paste DB_PASSWORD, salts, or secret keys into public tickets or screenshots. If you need to share the file with support, redact the password and salts first. Use the wp-config.php repair guide when credentials changed during migration.
When it is not a credential issue
If credentials are unchanged and the error is intermittent, check MySQL or MariaDB health, connection limits, disk pressure, host maintenance, and slow queries. The database health guide separates service health from WordPress configuration.
Diagnosis
Symptoms
- WordPress displays “Error establishing a database connection.”
- Admin and public pages fail while static assets may still load.
- Database login, host, user privileges, or service health changed recently.
Common causes
- Wrong database name, user, password, host, port, or socket.
- Database user lacks privileges on the WordPress database.
- MySQL or MariaDB is stopped, overloaded, out of disk, or rejecting connections.
- Table prefix does not match the installed WordPress tables.
- Recent migration or hosting change pointed the app at the wrong database.
Diagnostic Checklist
- Compare
wp-config.phpdatabase constants with the hosting panel. - Test database login from the web server when possible.
- Check MySQL or MariaDB service status, connection limits, and disk space.
- Confirm table prefix and required WordPress tables exist.
Fixes
Verify wp-config.php database settings
- 10 minutes
- Risk: medium
- Site owner
- WordPress, MySQL
Fix the most common WordPress database connection mismatch.
- Open
wp-config.phpfrom the active site root. - Compare
DB_NAME,DB_USER,DB_PASSWORD, andDB_HOSTwith the hosting control panel. - Check whether the host needs a port or socket.
- Save with original permissions and clear object cache if used.
WordPress can authenticate to the intended database.
If credentials are correct, test database service health and user privileges next.
Reload the site and wp-admin login.
Restore the previous wp-config.php if the edit made the error worse.
Check database service and user privileges
- 15 minutes
- Risk: medium
- Host admin
- MySQL, MariaDB
Find service outages, exhausted connections, or permission problems.
- Confirm MySQL or MariaDB is running.
- Test login using the WordPress database user from the web server.
- Check connection limits, disk space, and database error logs.
- Confirm the user has read/write privileges on the WordPress database.
The database accepts connections and WordPress has required privileges.
If login works but WordPress fails, inspect table prefix and application logs.
Load public and admin pages while watching database logs.
Undo temporary privilege changes that exceed the application need.
Platform notes
On managed WordPress hosting, database hostnames and passwords can change during migrations. On VPS setups, service health and local socket paths are as important as credentials.
FAQ
Is this always a WordPress problem?
No. WordPress displays the message, but the failure may be database service health, credentials, privileges, DNS, or hosting configuration.
Should I repair tables first?
Only after credentials and service health are confirmed and after taking a backup. Most connection errors are not table corruption.
Review notes
- Last reviewed
- 2026-05-05
- Reviewed by
- FaultForge Editorial Team, Web operations reviewer
- Tested on
WordPress wp-config.php database settings, MySQL and MariaDB service health checks, credential validation, and managed-hosting database status review.