If your WordPress website suddenly displays “Error establishing a database connection”, WordPress is unable to communicate with the database that stores your posts, pages, settings, users, and other site data.
The website may appear completely unavailable, and you may also lose access to wp-admin.
The good news is that the error does not automatically mean your database has been deleted. In many cases, the cause is incorrect database credentials, a temporary database server outage, damaged tables, exhausted hosting resources, or a problem after a migration.
QUICK ANSWER
To fix “Error establishing a database connection” in WordPress, first check whether your hosting database server is online. Then verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php. If those values are correct, check database-user privileges, hosting limits, and possible database corruption before restoring a backup or asking your host to inspect the database server.
What Does “Error Establishing a Database Connection” Mean?
WordPress stores most of your website’s content and settings in a database.
Each time someone opens your website, WordPress connects to that database, retrieves the required information, and builds the requested page.
If that connection fails, WordPress cannot retrieve the information it needs and may display:
Error establishing a database connection
The most common areas to investigate are:
- Incorrect database credentials
- An incorrect database host
- A database server that is offline or overloaded
- A database user without the correct privileges
- Database corruption
- Hosting resource or connection limits
- Incorrect settings after a migration or restore
BEFORE YOU START:
If possible, create a backup before editing wp-config.php, changing database users, repairing tables, or restoring an older database.
1. Check Whether the Database Server Is Down
Before editing WordPress files, check whether the problem is actually on the hosting side.
If your website was working normally and the database error appeared suddenly without any recent changes, a temporary database-server problem is an important possibility.
Check:
- Your hosting status page
- Your hosting dashboard for service alerts
- Whether phpMyAdmin or another database-management tool opens
- Whether other websites on the same hosting account are affected
If you cannot access the database through your hosting panel either, contact your hosting provider before changing WordPress configuration files.
Ask them to confirm:
- Whether the MySQL or MariaDB server is running
- Whether your database is available
- Whether your account has reached a database quota
- Whether the account has exceeded connection or resource limits
TIP:
If the error appears and disappears throughout the day, ask your host to check database connection limits and resource usage at the exact times the error occurs.
2. Verify the Database Details in wp-config.php
WordPress gets its database connection information from the wp-config.php file.
You can normally find this file in the main WordPress directory alongside folders such as:
wp-admin
wp-content
wp-includes
Open wp-config.php using your hosting File Manager, SFTP, or FTP.
Look for these settings:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_username' );
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'database_host' );
Compare them carefully with the database information displayed in your hosting control panel.
Check all four values:
- DB_NAME — the correct WordPress database
- DB_USER — the database username
- DB_PASSWORD — the current database password
- DB_HOST — the database server hostname
A single incorrect character can prevent WordPress from connecting.
SECURITY WARNING:
Never post your real database username or password in a public support forum, screenshot, email, or comment. Treat the credentials inside wp-config.php as sensitive information.
3. Make Sure DB_HOST Is Correct
Many WordPress installations use:
localhost
as the database host.
However, not every hosting provider uses localhost.
Your host may provide a custom hostname, IP address, port, or remote database server.
For example, the correct value could look different depending on the hosting environment.
Do not replace DB_HOST with a value you found in a random tutorial.
Instead, open your hosting control panel or contact hosting support and ask for the exact database hostname assigned to your WordPress database.
This is especially important after:
- Moving to a new host
- Restoring a backup
- Moving from local development to a live server
- Changing database servers
- Cloning a WordPress installation
4. Check the Database User and Privileges
Correct credentials are not enough if the database user is no longer assigned to the WordPress database or does not have the required privileges.
Open the database section of your hosting control panel.
Confirm that:
- The database still exists
- The database user still exists
- The correct user is assigned to the correct database
- The user has the permissions required by WordPress
This problem is particularly common after manual migrations, account restores, or database-user changes.
If you recently created a new database user, remember that the username and password in wp-config.php must match that user.
What If You Recently Changed the Database Password?
If the database password was changed in the hosting panel but wp-config.php still contains the old password, WordPress will immediately lose its database connection.
Update DB_PASSWORD so it matches the current password exactly.
Then save the file and reload the website.
5. Repair the WordPress Database If It Is Corrupted
If WordPress can reach the database server but one or more database tables are damaged, you may see a database repair message.
WordPress includes a built-in database repair tool.
Before using it, create a database backup if possible.
Open wp-config.php and add:
define( 'WP_ALLOW_REPAIR', true );
Then visit:
https://yourdomain.com/wp-admin/maint/repair.php
Replace yourdomain.com with your actual domain.
You should see options such as:
- Repair Database
- Repair and Optimize Database
Run the repair and review the result.
IMPORTANT:
Remove define( 'WP_ALLOW_REPAIR', true ); from wp-config.php immediately after the repair is finished. The repair page can be accessed without logging in while this feature is enabled.
If WordPress reports that a table cannot be repaired, stop repeating the repair process.
Use your hosting database tools, restore a known-good backup, or contact your hosting provider for help.
6. Check Database Connections, Disk Space, and Hosting Limits
If the error happens only during busy periods or appears intermittently, the problem may not be the password at all.
Your database server may be reaching a resource or connection limit.
Possible causes include:
- Too many simultaneous database connections
- A plugin repeatedly making expensive queries
- Bot or crawler traffic
- Insufficient hosting resources
- A database quota being reached
- Server disk space being exhausted
- A temporary MySQL or MariaDB failure
Look at the hosting resource-usage panel if one is available.
Also ask your host to check the database logs for messages related to:
- Maximum user connections
- Too many connections
- Disk or storage limits
- Database service restarts
- Resource throttling
USEFUL CLUE:
A wrong password normally causes a persistent connection failure. An error that appears only occasionally can point more strongly toward server availability, connection limits, or resource exhaustion.
7. Review Recent Migrations, Restores, and Hosting Changes
If the database error began immediately after moving or restoring the website, review the migration carefully.
Confirm that:
- The database was actually imported
- WordPress is pointing to the imported database
- The database username is assigned correctly
- The password matches wp-config.php
- The database hostname matches the new host
- The database server is online
A backup can restore WordPress files successfully while the database configuration still points to credentials from the old server.
That can make the migration look complete even though WordPress cannot connect to its new database.
When Should You Restore a Backup?
A backup may be appropriate if:
- Database tables are badly corrupted
- A repair process failed
- The database was accidentally modified or deleted
- The problem started immediately after a failed migration or restore
Before restoring, understand what newer content may be overwritten.
This is especially important for:
- WooCommerce orders
- User registrations
- Comments
- Form submissions
- Recent posts and edits
Is This the Same as a WordPress 500 Error?
No.
An Error Establishing a Database Connection specifically means WordPress cannot communicate properly with its database.
A 500 Internal Server Error is broader and can be caused by PHP errors, .htaccess rules, plugins, themes, permissions, server configuration, and other server-side failures.
If your site displays HTTP 500 instead of a database connection message, see our WordPress 500 Internal Server Error guide.
What If WordPress Shows a Critical Error Instead?
A WordPress critical error usually points to a fatal PHP problem rather than a basic database-login failure.
Plugins, themes, PHP compatibility, custom code, and memory limits are common areas to investigate.
See our WordPress Critical Error guide for the correct troubleshooting sequence.
Fastest Troubleshooting Order
If you want the shortest practical process, follow this order:
- Check whether your host’s database service is online.
- Back up wp-config.php before editing.
- Verify DB_NAME.
- Verify DB_USER.
- Verify DB_PASSWORD.
- Verify DB_HOST.
- Confirm the database user is assigned to the database.
- Check resource and database connection limits.
- Repair the database only if corruption is suspected.
- Review recent migration or restore changes.
- Contact your hosting provider with the exact error time and details.
Database Connection Error Quick Checklist
- ☐ Check hosting/database server status
- ☐ Back up important files and the database
- ☐ Verify DB_NAME
- ☐ Verify DB_USER
- ☐ Verify DB_PASSWORD
- ☐ Verify DB_HOST
- ☐ Confirm database-user privileges
- ☐ Confirm the database actually exists
- ☐ Check hosting resource limits
- ☐ Check database connection limits
- ☐ Repair corrupted tables if necessary
- ☐ Review recent migrations or restores
Frequently Asked Questions
What causes “Error establishing a database connection” in WordPress?
The most common causes are incorrect database credentials in wp-config.php, an incorrect database host, an unavailable database server, missing database-user privileges, resource limits, or database corruption.
Can a WordPress plugin cause a database connection error?
A plugin does not normally change the basic database credentials, but a poorly behaving plugin can create heavy database activity. In some hosting environments, excessive connections or resource usage may contribute to intermittent database failures.
Can I fix the database error without accessing wp-admin?
Yes. Most important checks are performed through your hosting control panel, File Manager, SFTP, FTP, phpMyAdmin, or hosting support. You do not need wp-admin to inspect wp-config.php.
Does this error mean my WordPress database is deleted?
No. The message only tells you that WordPress could not establish the required database connection. The database may still exist and be completely intact.
Why does the database connection error keep coming back?
An intermittent error can be caused by database-server instability, excessive concurrent connections, resource limits, storage problems, or an application repeatedly generating heavy database requests. Check the hosting logs and resource usage at the time of each failure.
Is it safe to use WP_ALLOW_REPAIR?
WordPress provides the repair feature for database troubleshooting, but it should only be enabled temporarily. Remove the WP_ALLOW_REPAIR setting from wp-config.php immediately after finishing because the repair page does not require a logged-in user while the feature is enabled.
Final Thoughts
When WordPress displays “Error establishing a database connection,” avoid immediately reinstalling WordPress or randomly changing plugins.
Start with the database server and the four connection values in wp-config.php: database name, username, password, and host.
If those are correct, investigate database-user privileges, hosting resource limits, connection limits, and database corruption.
The more precisely you identify whether the problem is credentials, database availability, corruption, or server capacity, the faster you can restore the site without causing additional damage.