TL;DR
The “Error establishing a database connection” message means WordPress cannot connect to the database it needs to load your website. Common causes include incorrect database credentials, an unavailable database server, or database-related problems.
To troubleshoot it:
- Check wp-config.php: Verify the database name, username, password, and host against your hosting configuration.
- Check database availability: If the credentials are correct, investigate whether your database server is running and accepting connections.
- Repair only when necessary: Database repair may help with damaged tables, but it won’t fix incorrect credentials or an unavailable server.
Before editing configuration files or attempting repairs, make sure you have a recent backup. If the database server is inaccessible, your hosting provider may need to investigate.
When WordPress displays “Error establishing a database connection,” your website may become inaccessible to visitors and administrators. The error appears when WordPress cannot establish the database connection required to retrieve content, settings, and other stored information.
What Causes the WordPress Database Connection Error?
The error message doesn’t identify the exact cause. The most useful starting point is to check when the error appeared and what changed immediately before it.
| What you’re experiencing | What to investigate first |
|---|---|
| The error appeared after a website migration |
Check the database name, username, password, and host in wp-config.php against the new hosting environment. |
|
The website stopped working without any recent changes |
Check whether the database server is available and whether your hosting provider has reported an outage. |
|
The error appears intermittently, then disappears |
Investigate temporary connection failures, database connection limits, and server resource usage. |
| The error started after editing wp-config.php |
Compare the database configuration with the last known working version. |
| You suspect damaged database tables |
Look for supporting database errors before attempting repairs. A connection error alone doesn’t confirm corruption. |
Before You Change Database Settings
Three precautions matter:
- Preserve the current database. Check whether your hosting account has a recent, usable backup. If the database is accessible, create a fresh export before attempting repairs. Avoid restoring an older backup without considering any newer content, orders, or user data it could overwrite.
- Locate your hosting configuration. You’ll need access to your hosting control panel or server files to inspect wp-config.php. Database names, users, and server addresses may differ between hosting environments.
- Keep credentials private. Never publish your database password or share an unredacted copy of wp-config.php. The file may contain authentication keys and other sensitive settings.
1. Check Your WordPress Database Credentials
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );What each setting controls:
- DB_NAME: The database WordPress should connect to.
- DB_USER: The MySQL or MariaDB user assigned to that database.
- DB_PASSWORD: The password associated with that database user.
- DB_HOST: The database server address. Depending on your hosting provider, this may be localhost, a specific hostname, or an address with a custom port.
Verify the settings against your hosting account
If your host uses cPanel, open MySQL Databases (sometimes called Manage My Databases).
Don’t reset the database password just to test the connection. Hosting dashboards generally don’t display existing database passwords. If you have a securely stored working credential, use it for verification. Otherwise, coordinate any password reset with your hosting provider and update wp-config.php accordingly.
2. Check Whether Your Database Server Is Running
Check database access through your hosting panel
If your hosting account includes phpMyAdmin, open it and check whether you can access the database used by WordPress.
Check for server interruptions and connection limits
- The MySQL or MariaDB service restarted or became unavailable when the error appeared.
- Database connection limits were reached.
- Server memory, CPU, or other resource limits affected database availability.
Avoid restarting the database service without confirming the cause. On shared hosting, this is normally managed by the provider. On a VPS or dedicated server, restarting MySQL or MariaDB can interrupt other applications using the same database service.
3. Repair the WordPress Database – Only If Tables Are Damaged
Use WordPress’s built-in database repair tool
1. Open wp-config.php through your hosting File Manager or SFTP.
2. Add the following line before /* That's all, stop editing! Happy publishing. */, or the equivalent end-of-configuration comment: define( ‘WP_ALLOW_REPAIR’, true );
3. Save the file and visit https://yourdomain.com/wp-admin/maint/repair.php, replacing yourdomain.com with your website’s domain.
4. Select Repair Database and review the results.
Remove the WP_ALLOW_REPAIR line immediately after the repair attempt, even if the problem persists. While enabled, the repair page can be accessed without logging into WordPress.
What if the database repair fails?
Check the reported table errors and contact your hosting provider before attempting further repairs. Some database storage engines and types of corruption require different recovery methods.
4. Check for Missing or Corrupted WordPress Files
Verify WordPress core files
wp core verify-checksumsA failed checksum check identifies files that differ from the expected version, but it doesn’t automatically confirm that those differences caused the database connection error.
Replace files only when necessary
5. Investigate Recent Changes and Persistent Database Errors
Database connection error after a WordPress migration
Intermittent WordPress database connection errors
What to Send Your Hosting Provider
- Affected website: The domain and whether the error affects the entire site or only occurs intermittently.
- When it started: The approximate time, time zone, and whether the error followed a migration, update, or hosting change.
- Checks already completed: Whether the database exists, the database user has the required permissions, and phpMyAdmin can access it.
- Relevant error messages: Any database or PHP errors you’ve found, with sensitive information removed.
Ask your provider to check the MySQL/MariaDB service status, database connection limits, server resource usage, and relevant error logs around the time of the failure.
When to Get Professional WordPress Help
- The error persists after migration. The database exists, but WordPress still cannot connect using the configured credentials.
- Database permissions or configuration need further investigation. The issue involves database user privileges, custom server settings, or application-level connection errors.
- A repair attempt fails. Database checks reveal damaged tables or errors that cannot be resolved safely through the standard repair tool.
- The website contains important live data. Further changes could affect recent orders, user accounts, or other information that has not been backed up.
For WordPress-side issues, Kiwistic’s One-Time Fix service provides a way to request technical assistance without committing to a monthly maintenance plan. Describe the error, when it started, and which checks you’ve already completed so the problem can be assessed before work begins.
How to Reduce the Risk of Recurring Database Errors
- Keep recoverable database backups. Check that backups are running and periodically verify that they can be restored.
- Document configuration changes. Record database hostname, user, or server changes during migrations and hosting updates. Store sensitive credentials securely, not in public documents.
- Monitor recurring interruptions. If connection errors appear during traffic spikes or scheduled tasks, investigate the corresponding server logs and resource usage.
- Check the site after migrations. Confirm that WordPress connects to the intended database before considering the migration complete.
Conclusion
If the problem persists, use the evidence you’ve collected to determine whether your hosting provider or a WordPress developer needs to investigate further. Avoid repeated configuration changes without identifying the cause, particularly on websites with active customer or transaction data.
FAQ
Does a database connection error mean my WordPress data is lost?
Before attempting to restore or replace the database, check whether it exists and whether your hosting provider can access it.
Can I fix the database connection error without WordPress admin access?
Some problems require assistance from your hosting provider, particularly when the database server is unavailable or access is restricted.
Will reinstalling WordPress fix a database connection error?
Reinstalling WordPress core files may be appropriate when file corruption has been confirmed, but it won’t automatically repair a damaged database or restore a failed server connection. Identify the cause before replacing files.


