How to Fix the Error Establishing a Database Connection in WordPress
Seeing the message “Error Establishing a Database Connection” on your WordPress website can be alarming. Your homepage may stop loading, visitors may be unable to access your content, and even your WordPress admin dashboard may become unavailable.
This error means WordPress cannot establish a working connection to the database that stores your website’s posts, pages, user accounts, settings, and other important information.
The good news is that your website content is not necessarily lost. In many cases, the problem is caused by incorrect database credentials, a database server outage, insufficient database permissions, or damaged database tables.
In this guide, you will learn how to troubleshoot the WordPress database connection error step by step. You will also learn how to check your wp-config.php file, verify database credentials, investigate MySQL server problems, and use WordPress database repair tools safely.
Important: Create a complete backup of your website files and database before changing configuration files or attempting database repairs. If you are not comfortable working with database settings, ask your hosting provider for assistance.
What Does Error Establishing a Database Connection Mean?
WordPress uses a database, usually MySQL or a compatible database server, to store and retrieve website information.
Whenever a visitor opens a WordPress page, WordPress communicates with the database to retrieve the content and settings needed to display that page.
If WordPress cannot connect to the database, it may display this message:
Error Establishing a Database Connection
This means WordPress cannot complete the database connection process. It does not automatically mean that your database has been deleted or that your content is permanently lost.
The problem may involve database login information, server availability, permissions, or database integrity.
Common Causes of WordPress Database Connection Errors
Understanding the possible causes will help you troubleshoot the problem without making unnecessary changes.
| Possible cause | Explanation |
|---|---|
| Incorrect database credentials | Database name, username, or password does not match the actual database account |
| Incorrect database host | The DB_HOST value points to the wrong database server |
| Database server outage | MySQL or MariaDB is temporarily unavailable |
| Missing database permissions | The database user does not have the required privileges |
| Damaged database tables | One or more database tables may be corrupted or unavailable |
| Hosting resource limits | The database server may have reached its connection or resource limits |
| Recent website migration | Database details may not have been updated after moving the website |
| Configuration changes | An incorrect edit to wp-config.php may prevent WordPress from connecting |
Not every database connection error requires a database repair. First determine whether WordPress cannot log in to the database or whether the database itself has a problem.
Step 1: Check Whether Your Hosting Database Server Is Working
Start by checking whether your hosting provider is experiencing a database or server outage.
Sometimes the problem is not related to WordPress at all. Your hosting provider may temporarily stop database services because of maintenance, server issues, resource limits, or an unexpected outage.
Follow these steps:
- Open your hosting account.
- Check the hosting provider’s service status page, if available.
- Look for database, MySQL, or MariaDB service problems.
- Check whether other websites on the same hosting account are also affected.
- Open phpMyAdmin if your hosting account provides access to it.
If phpMyAdmin is unavailable or reports a connection problem, the database server may be experiencing an issue.
What should you do?
Contact your hosting provider and ask them to check:
- Whether the MySQL or MariaDB service is running.
- Whether the database server is accepting connections.
- Whether your database has reached its resource or storage limits.
- Whether the hosting account has any database restrictions.
- Whether there are server-side errors affecting your database.
Do not change your database password or WordPress configuration until you know whether the database server is available.
Step 2: Create a Complete Website Backup
Before editing database settings or attempting repairs, create a full backup.
Your backup should include:
- WordPress website files.
- The complete WordPress database.
- Themes and plugins.
- Uploaded images and media.
- The
wp-config.phpconfiguration file.
You can normally create backups through your hosting control panel or a WordPress backup plugin.
Create a Database Backup Through phpMyAdmin
If phpMyAdmin is available:
- Log in to your hosting control panel.
- Open phpMyAdmin.
- Select the database used by your WordPress website.
- Open the Export tab.
- Select the Quick export method if appropriate.
- Choose SQL as the export format.
- Start the export.
- Save the downloaded SQL file securely.
The exact interface may differ depending on your hosting provider and phpMyAdmin version.
Keep the backup in a safe location outside your public website directory. Never overwrite your only backup with an unverified copy.
For a routine maintenance process, see our WordPress Maintenance Checklist.
Step 3: Check Your wp-config.php Database Settings
The wp-config.php file contains important configuration settings that WordPress uses to connect to its database.
Incorrect database information in this file is a common reason for connection errors.
Locate the wp-config.php File
You can access this file through:
- Your hosting File Manager.
- An FTP client.
- A secure file-management tool provided by your hosting company.
Follow these steps:
- Open your hosting control panel.
- Launch File Manager.
- Open the directory where WordPress is installed.
- Locate
wp-config.php. - Download a copy before editing it.
- Open the file using the File Manager editor.
Look for a section similar to this:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_username' );
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'localhost' );Your actual values may be different.
These settings have specific purposes:
DB_NAME: The name of your WordPress database.DB_USER: The database username.DB_PASSWORD: The password assigned to that database user.DB_HOST: The database server hostname.
Compare these values with the database information shown in your hosting control panel.
Important: Do not copy the example values into your website. Replace incorrect values only with the actual credentials supplied by your hosting provider.
Do not share your real database password publicly or paste your complete wp-config.php file into an online forum.
Step 4: Verify Database Name and Username
A database name or username mismatch can prevent WordPress from connecting to the database.
This problem commonly occurs after:
- Moving a website to another hosting provider.
- Creating a new database.
- Changing database credentials.
- Restoring a website backup.
- Migrating a website manually.
Check Your Database Information
- Open your hosting control panel.
- Find the MySQL or database management section.
- Locate the database associated with your WordPress installation.
- Note its exact database name.
- Check which database username is assigned to it.
- Compare both values with
DB_NAMEandDB_USERinwp-config.php.
Some hosting providers automatically add an account prefix to database names and usernames.
For example, a database might appear as:
accountname_wordpressIf the actual database name includes a prefix, the same complete name must be used in wp-config.php.
What If the Database Password Is Incorrect?
If the password in wp-config.php does not match the current database user’s password, WordPress may be unable to connect.
You can resolve this by:
- Opening the database management section of your hosting account.
- Identifying the correct database user.
- Changing or resetting its password if necessary.
- Updating the
DB_PASSWORDvalue inwp-config.phpwith the new password. - Saving the file.
- Testing the website.
Make sure you update the correct database user’s password. Changing the password without updating WordPress configuration can create another connection error.
Step 5: Check Database User Permissions
Having the correct database name and password is not always enough. The database user must also have the necessary permissions to access and work with the WordPress database.
If the database user has been removed, replaced, or assigned insufficient permissions, WordPress may fail to connect or perform database operations.
Verify Database User Privileges
- Open your hosting control panel.
- Go to the MySQL database management section.
- Find the database associated with your WordPress website.
- Check which user is assigned to that database.
- Review the assigned privileges.
- Confirm that the user has the permissions required by WordPress.
For a typical WordPress installation, the database user needs the privileges required to read and update website data and manage database tables during normal operations and updates.
If you are unsure which privileges are appropriate, ask your hosting provider to verify the database user’s permissions.
Do not assign unnecessary privileges to unrelated database users.
Step 6: Check the Database Host (DB_HOST)
The DB_HOST setting tells WordPress where the database server is located.
Many hosting environments use:
define( 'DB_HOST', 'localhost' );However, localhost is not correct for every hosting provider.
Some providers use a separate database hostname or server address.
How to Find the Correct Database Host
- Open your hosting control panel.
- Find your database information.
- Look for the database hostname or server address.
- Compare it with the
DB_HOSTvalue inwp-config.php. - Contact hosting support if the correct hostname is not displayed.
For example, your hosting provider might specify a hostname such as:
define( 'DB_HOST', 'mysql.example-host.com' );This is only an illustrative example. Use the actual hostname supplied by your provider.
Do not assume that changing localhost to another value will fix the problem. An incorrect hostname can create the same connection error.
Step 7: Check Whether Your Database Tables Are Damaged
If your database credentials and server connection appear correct, investigate whether the database tables are damaged or unavailable.
In some cases, WordPress may display a more specific message in the admin area, such as:
One or more database tables are unavailable. The database may need to be repaired.
This is different from an ordinary database login failure.
Check Database Tables Through phpMyAdmin
- Open your hosting control panel.
- Launch phpMyAdmin.
- Select the correct WordPress database.
- Review the list of database tables.
- Look for tables marked as crashed, unavailable, or in an error state.
- Record the affected table names.
WordPress database tables often use the wp_ prefix, but your installation may use a different prefix.
For example:
wp_posts
wp_users
wp_options
wp_comments
wp_postmetaDo not assume that every installation uses the wp_ prefix.
If a table appears damaged, make sure you have a complete database backup before attempting a repair.
Important: Do not delete database tables simply because they appear unfamiliar. Some plugins create their own tables, and removing them can cause data loss.
Step 8: Repair the WordPress Database Safely
If you have confirmed that database tables are damaged or unavailable, you may be able to use WordPress’s built-in database repair page.
This method is intended for database table repair, not for fixing incorrect database credentials or an unavailable database server.
Method A: Use WordPress Built-in Database Repair
First, make sure you have a complete database backup.
Open wp-config.php and add this line before the final stop-editing comment:
define( 'WP_ALLOW_REPAIR', true );Save the file.
Next, open this address in your browser:
https://yourdomain.com/wp-admin/maint/repair.phpReplace yourdomain.com with your actual domain.
If WordPress can load the repair page, you may see options such as:
- Repair Database
- Repair and Optimize Database
Read the information displayed on the page before proceeding.
Run the repair only if the database condition makes it appropriate. This tool does not resolve incorrect credentials, missing database permissions, or an unavailable MySQL server.
Critical security warning: The built-in repair page does not require a normal WordPress administrator login once repair mode is enabled. Anyone who can access the URL may be able to trigger a repair operation while the setting is active.
Therefore:
- Enable the setting only when needed.
- Run the repair promptly.
- Remove
define( 'WP_ALLOW_REPAIR', true );fromwp-config.phpimmediately afterward. - Save the file.
- Confirm that the repair page is no longer publicly enabled.
Do not leave database repair mode enabled on a live website.
Method B: Repair Tables Through phpMyAdmin
If your hosting provider supports table repair for the affected database engine:
- Open phpMyAdmin.
- Select the correct database.
- Identify the affected table.
- Select only the table that requires repair.
- Use the available repair option if it is supported.
- Check the table status again.
Important: Repair operations depend on the database storage engine. For example, the MySQL REPAIR TABLE operation is not supported for InnoDB tables in the same way it is for MyISAM tables.
Do not repeatedly run repair commands on an InnoDB table. Ask your hosting provider to investigate the database engine and server logs if the table remains unavailable.
If a repair fails, stop and contact hosting support rather than experimenting with SQL commands on a live database.
Step 9: Check Hosting Resources and Server Logs
Sometimes the database credentials are correct, but the database server cannot accept new connections.
This may happen because of:
- High website traffic.
- Too many simultaneous database connections.
- Hosting resource limits.
- Database server downtime.
- Insufficient disk space.
- Long-running database queries.
- Server configuration problems.
What to Check
Open your hosting dashboard and review the available resource information.
Look for:
- CPU usage.
- Memory usage.
- Disk space.
- Database storage usage.
- Database connection limits.
- Hosting account resource restrictions.
If your hosting provider offers MySQL or database error logs, review the entries around the time the website stopped working.
You may see errors related to connection limits, unavailable services, or database storage.
Contact Hosting Support
If the database server is unavailable or you cannot identify the cause, send your hosting provider a clear support request.
You can use this message:
Subject: WordPress Error Establishing a Database Connection
Hello Support Team,
My WordPress website is displaying the message “Error Establishing a Database Connection.”
I have started checking the database credentials and WordPress configuration. Could you please verify:
- Whether the MySQL or MariaDB service is running.
- Whether my database is available and accepting connections.
- Whether the database user has the correct permissions.
- Whether the database has reached any connection, storage, or resource limits.
- Whether there are any database server errors in the logs.
Please investigate the issue and let me know what is causing the connection failure.
Thank you.
Step 10: Review Recent Website Changes
If the error started immediately after a website migration, database password change, hosting update, or configuration edit, review those changes.
Consider the following questions:
- Was the website recently moved to another hosting provider?
- Was the database password changed?
- Was a new database created?
- Was
wp-config.phpedited? - Were database users or permissions modified?
- Did the hosting provider change the database hostname?
- Was a backup recently restored?
Compare the current configuration with a known working backup if one is available.
If the error started after a migration, confirm that the database name, username, password, hostname, and table prefix match the new hosting environment.
Do not reinstall WordPress or create a replacement database simply because the connection error appears. First establish whether the existing database is accessible and contains your website data.
Step 11: Test Your Website After the Fix
After correcting the connection problem, test your website carefully.
Use this checklist:
- Homepage loads normally.
- WordPress admin dashboard opens.
- Posts and pages display correctly.
- Images and media files load.
- Navigation menus work.
- Contact forms work.
- Users can log in where applicable.
- Important plugins function normally.
- No new database connection errors appear.
- Database repair mode is disabled.
- Temporary diagnostic files have been removed or secured.
If the website is still unavailable, do not keep changing random database settings. Record the exact error message and ask your hosting provider to investigate the server-side database connection.
How to Prevent WordPress Database Connection Errors
You cannot prevent every database or hosting problem, but regular maintenance can reduce the risk and make recovery easier.
1. Keep Database Credentials Secure
Store database credentials safely and avoid unnecessary changes to wp-config.php.
If you change a database user’s password, update the WordPress configuration at the same time.
2. Maintain Regular Backups
Back up both your website files and database. Keep copies outside your public website directory and periodically verify that they can be restored.
3. Monitor Hosting Resources
Check disk space, database storage, and resource usage. Contact your hosting provider if your website regularly approaches its limits.
4. Use Reliable Hosting
Choose hosting with reliable database services, adequate resources, and responsive technical support.
5. Avoid Unnecessary Database Changes
Do not delete database tables, change user privileges, or run SQL commands without understanding their effects.
6. Test Website Migrations Carefully
After moving a website, verify database credentials, database hostname, user permissions, and table prefixes before switching visitors to the new server.
7. Maintain WordPress Regularly
Review plugins, themes, backups, and website functionality on a regular schedule.
Our WordPress Maintenance Checklist provides a useful routine for keeping your website maintained.
Frequently Asked Questions
1. What causes the WordPress Error Establishing a Database Connection?
The error usually occurs when WordPress cannot connect to its database. Common causes include incorrect database credentials, an incorrect database hostname, missing user permissions, a database server outage, or damaged database tables.
2. Will I lose my WordPress content if this error appears?
Not necessarily. Your posts, pages, users, and settings are generally stored in the database. A connection error does not automatically mean that this information has been deleted. Avoid reinstalling WordPress or creating a new database before checking the existing one.
3. How do I fix a database connection error in wp-config.php?
Open wp-config.php through your hosting File Manager or FTP. Check the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST values against the actual database information provided by your hosting provider. Correct any mismatched values carefully.
4. Can a hosting server cause a WordPress database connection error?
Yes. A database service outage, resource limit, connection limit, or server configuration problem can prevent WordPress from connecting even when the database credentials are correct.
5. Does disabling WordPress plugins fix a database connection error?
Usually, disabling plugins is not the first troubleshooting step for a genuine database connection failure. WordPress needs a database connection before it can normally load plugins. Check the database server and credentials first. Investigate plugins only when the connection works but another PHP or application error appears.
6. How do I repair a WordPress database?
First create a complete database backup. If WordPress reports damaged or unavailable tables, investigate the affected tables through phpMyAdmin or use the built-in WordPress repair tool when appropriate. Always remove the WP_ALLOW_REPAIR setting immediately after using the built-in repair page.
7. Should I reinstall WordPress to fix this error?
No, not as an initial troubleshooting step. Reinstalling WordPress does not automatically fix incorrect database credentials, database server outages, or missing database permissions. Identify the underlying problem before considering a reinstallation.
Final Thoughts
The WordPress Error Establishing a Database Connection can make your entire website unavailable, but it does not automatically mean that your content is lost.
Start by checking your hosting database server and creating a complete backup. Then verify the database credentials in wp-config.php, confirm user permissions, and investigate database tables only when there is evidence of damage.
If the database server is unavailable or the problem continues after checking the configuration, contact your hosting provider with the exact error details.
A careful troubleshooting process is safer than randomly changing database settings, reinstalling WordPress, or deleting website files.
Official Resources
For additional technical information, consult these official WordPress resources:




