A WordPress site can go from working normally to displaying one short message:
Error establishing a database connection
When that happens, the homepage may disappear, /wp-admin/ may become inaccessible, and refreshing the page usually does nothing useful.
The WordPress error establishing a database connection means WordPress cannot communicate with the database it needs to build the requested page. Your posts, pages, settings, users, plugin options, WooCommerce data, and much of the site’s configuration live in that database. If WordPress cannot reach it, the site cannot operate normally.
The useful part is that the message narrows the problem considerably. Unlike a generic server error, you already know where to investigate: the database credentials, database server, database condition, or the connection between WordPress and that server.
This guide walks through a controlled troubleshooting process, starting with the checks least likely to make the situation worse.
Key Takeaways
- The error means WordPress cannot successfully connect to the database it is configured to use.
- Incorrect wp-config.php database credentials are common, but they are not the only possible cause.
- Check recent changes and hosting status before editing files or repairing the database.
- Verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST carefully.
- An intermittent error often points toward database-server availability, resource limits, or hosting problems rather than permanently incorrect credentials.
- Use WordPress’s database repair feature only when there is evidence of database corruption.
- Back up the website before changing configuration files, repairing tables, restoring databases, or making server-level changes.
What the Database Connection Error Actually Means
A typical WordPress request depends on both website files and database data.
The PHP files tell WordPress how to operate. The database stores much of the information WordPress needs to determine what to display. During a request, WordPress loads the connection values defined in wp-config.php and attempts to connect to its MySQL-compatible database server.

WordPress’s official common errors documentation identifies incorrect information in wp-config.php and hosting/database-server problems among the main causes of an “Error establishing a database connection.”
The four settings most directly involved are:
define( ‘DB_NAME’, ‘database_name’ );
define( ‘DB_USER’, ‘database_username’ );
define( ‘DB_PASSWORD’, ‘database_password’ );
define( ‘DB_HOST’, ‘database_host’ );
These are not WordPress administrator credentials. They are credentials WordPress itself uses to connect to the database.
Common causes at a glance
| Possible cause | Common clue | Best first check |
| Wrong database password | Error starts after password or hosting changes | Compare wp-config.php with hosting database credentials |
| Wrong database name or username | Error begins after migration or manual edits | Verify all four database constants |
| Wrong database host | New host or remote database was recently configured | Confirm the host value with your provider |
| Database server unavailable | Multiple sites or services are affected | Check hosting status or contact support |
| Database corruption | Error follows a crash or database issue | Check tables and consider WordPress repair tools |
| Resource or connection limits | Error appears intermittently under load | Review database/server logs and resource usage |
| Failed migration | Site worked on the old server but not the new one | Check imported database and environment configuration |
| Compromised or altered configuration | Unexpected changes appear without legitimate admin work | Preserve evidence and investigate the site’s security |
Before changing anything, ask:
What happened immediately before the error appeared?
That one question can eliminate unnecessary troubleshooting.
For example, suppose a business website was migrated from one hosting provider to another and immediately began showing the database connection error. Plugin troubleshooting would be a poor starting point. Database credentials, hostname, database import status, and the new hosting environment are much more likely suspects.
The same principle applies across WordPress troubleshooting. If the site instead displays a blank page, use a dedicated WordPress White Screen of Death troubleshooting process. If the server returns a generic HTTP 500 response, the WordPress 500 internal server error guide covers additional PHP, .htaccess, plugin, and server-level causes.
How to Fix the WordPress Error Establishing a Database Connection
Work through these steps in order unless you already have reliable logs or hosting information identifying the cause.
Changing several variables simultaneously makes troubleshooting harder because you will not know which action restored the site.
1. Protect the Current Site Before Editing Anything
If you have access to your hosting account, take a backup before changing configuration files, repairing database tables, restoring an older database, or modifying database users.
Ideally, preserve both:
- Website files
- The current database
Even a damaged database can contain recent orders, form submissions, customer records, account changes, posts, or other information that is newer than your last clean backup.
Do not overwrite the current database with an old backup just because the site is down.
A site that processes orders or bookings could be technically restored while simultaneously losing recent business records.
WordPress also recommends having an appropriate backup or staging environment before making debugging modifications.
2. Check Whether the Database Server Is Actually Available
Before editing wp-config.php, determine whether the failure may be outside WordPress.
Open your hosting control panel and check for:
- Database server warnings
- Service outages
- Account resource limits
- Disk-space problems
- Database-storage limits
- MySQL or MariaDB service status
- Maintenance notices
If your hosting provider has a status page, check it.
You can also try opening the database through the provider’s normal database-management interface, such as phpMyAdmin if available. Failure there does not automatically prove the database server is down, but it gives you another useful clue.
If the error appeared suddenly even though nobody changed the WordPress configuration, hosting availability deserves attention before you start rewriting credentials.
WordPress specifically recommends contacting the web host when the configuration appears correct because a database quota or unavailable server can also cause the error.
3. Check the wp-config Database Credentials
The next step is the most important wp-config database credentials check.
Locate wp-config.php. In a typical installation, it is in the root WordPress directory alongside folders such as:
wp-admin
wp-content
wp-includes
Access may be available through:
- Your hosting File Manager
- SFTP
- SSH
- Another file-management method provided by your host
Open the file carefully and locate:
define( ‘DB_NAME’, ‘…’ );
define( ‘DB_USER’, ‘…’ );
define( ‘DB_PASSWORD’, ‘…’ );
define( ‘DB_HOST’, ‘…’ );

WordPress’s wp-config documentation explains the database configuration and other settings contained in this file.
Compare each value with the current credentials shown in your hosting environment.
DB_NAME
DB_NAME must reference the database containing this particular WordPress installation.
This becomes especially important when a hosting account contains several websites or databases with similar names.
A migration might import the correct database under a new name while wp-config.php still points to the old one.
DB_USER
DB_USER must be a database user that can access the WordPress database.
Creating a database does not necessarily mean every database user on the hosting account automatically has access to it.
Check both the username and its database assignment.
DB_PASSWORD
DB_PASSWORD must exactly match the current password for the database user.
A common failure sequence looks like this:
- Someone resets the database user’s password in the hosting panel.
- The hosting database now expects the new password.
- wp-config.php still contains the old password.
- WordPress can no longer authenticate.
If you intentionally reset the database-user password, update the corresponding value in wp-config.php.
Do not confuse this password with your WordPress administrator password, hosting password, or SFTP password.
DB_HOST
DB_HOST identifies where the database server can be reached.
Many installations use:
define( ‘DB_HOST’, ‘localhost’ );
But localhost is not universal.
A hosting company may provide another hostname, IP address, socket configuration, or host-and-port combination. WordPress’s installation documentation notes that DB_HOST is usually localhost, but not always.
Use the database hostname supplied by your hosting provider rather than guessing.
4. Confirm the Database User Still Has Access
Correct-looking credentials are not enough if the database user has lost permission to the database.
In your hosting control panel, verify that:
- The expected database exists.
- The expected database user exists.
- The user is assigned to that database.
- The account has the permissions required by the WordPress installation.
This check is particularly worthwhile after:
- Hosting migrations
- Database-user changes
- Account restores
- Server moves
- Security remediation
- Manual database administration
Consider a simple scenario.
A developer migrates example.com from Server A to Server B. The database is successfully imported, and wp-config.php contains the correct database name, username, and password. However, the newly created database user was never assigned to the imported database.
Everything appears correct at first glance, yet WordPress still cannot use the database.
The fix is not another WordPress installation. It is correcting the database-user assignment.
5. Check Whether the Database Itself Is Damaged
If the server is running and the credentials are correct, database corruption becomes another possibility.
Do not begin repairing tables simply because WordPress displays a connection error. Repair is appropriate when you have evidence suggesting damaged database tables or WordPress reports that tables need repair.
WordPress includes a built-in WordPress repair database feature.
To enable it temporarily, add this line to wp-config.php:
define( ‘WP_ALLOW_REPAIR’, true );
You can then access:
https://example.com/wp-admin/maint/repair.php
WordPress provides options to repair the database or repair and optimize it. Its official documentation confirms the WP_ALLOW_REPAIR method and warns that the repair page does not require a logged-in user while the option is enabled.
For that reason, remove the line as soon as you are finished.
Do not leave:
define( ‘WP_ALLOW_REPAIR’, true );
enabled permanently.
Also avoid treating database optimization as a generic fix for every connection problem. It will not correct a wrong password, restore an unavailable MySQL server, or repair a network connection.
6. Review What Changed During a Migration or Restore
Database-connection errors are especially common around migrations because several dependent pieces change at once.
Check:
- Was the database actually imported?
- Does DB_NAME reference the newly imported database?
- Was the database user created on the destination server?
- Was that user assigned to the database?
- Was its password updated correctly?
- Is DB_HOST different on the new host?
- Did the migration restore an older wp-config.php?
- Did a staging configuration accidentally replace the production configuration?
Do not start replacing URLs inside the database until basic connectivity works.
A siteurl problem can send WordPress to the wrong domain after the database is loaded. It does not normally explain why WordPress cannot authenticate to the database in the first place.
7. Check Server Logs When the Obvious Fixes Fail
If the error persists, logs become more useful than continued guessing.
Depending on your hosting environment, inspect:
- Database-server logs
- PHP logs
- Hosting error logs
- Web-server logs
- Resource monitoring
- Disk and memory usage
- Connection-limit information
WordPress also provides built-in debugging options documented in its WordPress debugging guide.
Be careful not to expose debug information publicly on a production site. Logging errors privately is generally more appropriate than displaying technical messages to every visitor.
If troubleshooting WordPress failures is becoming a recurring maintenance task rather than a one-time outage, a structured WordPress site maintenance process can make backups, testing, monitoring, and recovery much more predictable.
How to Diagnose Less Obvious Database Connection Problems
Not every database failure is permanent. How the error behaves can help narrow the cause.

The error appears only occasionally
An intermittent connection error is different from an error that started immediately after changing a database password.
If the exact same wp-config.php works at 10:00 a.m., fails at 10:05, and works again later without anybody changing it, incorrect static credentials become less likely.
Investigate:
- Database server instability
- Resource exhaustion
- Connection limits
- High traffic or automated activity
- Slow database queries
- Server disk-space problems
- Hosting infrastructure issues
Do not keep rewriting wp-config.php if the existing credentials demonstrably work part of the time.
The homepage and wp-admin both fail
That pattern is expected when WordPress cannot make the database connection at all.
Your dashboard is not independent of the database. WordPress needs the database to authenticate administrators, load options, determine installed configuration, and build admin pages.
You therefore cannot assume that /wp-admin/ will remain available for fixing the problem.
File access, database tools, or your hosting account may be required.
The public site works but wp-admin shows another error
Do not automatically treat every WordPress admin failure as a database-connection problem.
A plugin, theme, PHP error, permissions issue, or partial failure can affect only certain requests.
Diagnose the message actually being produced.
For example, a genuine HTTP 500 response deserves a broader server-side investigation rather than repeatedly changing database credentials.
The problem started after changing hosts
Start with the environment rather than plugins.
A practical order is:
- Confirm the database exists on the destination server.
- Confirm the import completed.
- Confirm the database username.
- Confirm the password.
- Confirm that the user has access to the database.
- Confirm the new DB_HOST.
- Check the host’s database service.
- Only then investigate secondary WordPress issues.
This keeps migration troubleshooting focused on the systems most likely to have changed.
The error suddenly appeared on a previously stable site
If the site had been stable for months and nobody knowingly changed the database settings, investigate the hosting environment and recent administrative activity.
Also verify that wp-config.php has not been unexpectedly modified.
Unexpected changes can result from an accidental deployment, failed restore, unauthorized access, or other configuration problem.
If you find suspicious files, unknown administrators, unauthorized database users, or other indicators of compromise, stop treating the incident as a routine configuration error. Website cleanup requires a broader security investigation. Websites USA’s guide to cleaning malware from WordPress explains why WordPress recovery needs to address both files and database content rather than simply restoring visible pages.
When You Should Stop Troubleshooting and Get Help
Editing a single incorrect database value is manageable for many site owners.
The risk changes when you begin dealing with production databases, server configurations, live orders, customer information, or an unexplained outage.
Professional assistance becomes more sensible when:
- You do not have a verified backup.
- The site processes payments or orders.
- The database contains recent customer submissions that cannot be recreated.
- The error is intermittent and server resources need investigation.
- Database credentials are correct but authentication still fails.
- Several websites on the server fail simultaneously.
- Database tables appear corrupted.
- The problem began during a complicated migration.
- You suspect unauthorized access.
- Restoring the wrong database could destroy newer records.
- You are not comfortable editing wp-config.php, database users, or server settings.
Business impact matters too.
Imagine an informational brochure website and an eCommerce store both go offline with the same database error.
Technically, the message is identical.
Operationally, they are very different incidents.
The brochure site may temporarily lose contact-form leads. The store may lose checkouts while also creating a risk that an older database restoration overwrites orders placed shortly before the outage.

The recovery plan should account for what is stored in the database, not merely how quickly a homepage can be made visible again.
Businesses that prefer ongoing monitoring, backups, testing, and technical troubleshooting can also use a managed website maintenance service rather than waiting for each production failure to become an emergency.
A practical database error checklist
Before declaring the issue solved, confirm each of these items:
- A current backup has been preserved.
- The database service is available.
- DB_NAME matches the correct database.
- DB_USER matches the intended database user.
- DB_PASSWORD is current.
- DB_HOST matches the hosting environment.
- The database user has access to the correct database.
- The database contains the expected WordPress tables.
- Any database repair was performed only when necessary.
- WP_ALLOW_REPAIR was removed after use.
- The public website loads normally.
- /wp-admin/ works.
- Forms, checkout, login, or other database-dependent functions work.
- The site’s error and database logs show no continuing failure.
- The original cause has been documented rather than merely bypassed.
The last point is easy to skip.
A site that happens to start working again has not necessarily been fixed. If the root cause was exhausted resources or an unstable database server, the same failure may return during the next traffic spike.
Make Database Problems Easier to Recover From
The best error establishing a database connection fix is not the one that involves the most technical changes. It is the one that identifies which part of the connection failed and changes only what is necessary.
Start with recent changes and hosting availability. Verify the wp-config.php credentials carefully. Check database-user access. Investigate corruption only when the evidence points there. Use logs when simple checks stop providing answers.
Most importantly, treat the database as business data rather than just another WordPress component. A disciplined backup and troubleshooting process protects both the website and the information the business cannot easily recreate.
FAQs
What causes “Error establishing a database connection” in WordPress?
The most common areas to investigate are incorrect database details in wp-config.php, an unavailable database server, database-user permission problems, hosting resource issues, or database corruption. Recent migrations, password changes, and restores can also introduce configuration mismatches.
How do I check my WordPress database credentials?
Open wp-config.php through your hosting File Manager, SFTP, or another secure file-access method. Compare DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST with the current database information supplied by your hosting provider.
Can a WordPress plugin cause a database connection error?
Plugins can create database-related problems or place heavy demand on the database, but the standard connection error usually means WordPress could not establish the required database connection. Do not begin by disabling every plugin unless logs or recent changes provide a reason to investigate one.
How do I repair a WordPress database?
WordPress includes a repair utility that can be temporarily enabled with WP_ALLOW_REPAIR in wp-config.php. Back up the database first, use the repair function only when appropriate, and remove the setting afterward because the repair page can be accessible without normal WordPress authentication while enabled.
Why does the database connection error keep coming and going?
An intermittent error may point toward server availability, database connection limits, resource pressure, disk-space problems, or hosting infrastructure rather than permanently wrong credentials. Review server logs and resource data from the times when the failures occur.
Can I fix the error without access to wp-admin?
Yes. In fact, a genuine database connection failure commonly prevents WordPress admin from loading because the dashboard also depends on the database. You may need your hosting control panel, File Manager, SFTP, SSH, phpMyAdmin, or assistance from the hosting provider instead.
Will restoring a backup fix the database connection error?
It can help when the current database or configuration has been damaged, but restoring a backup is not automatically the correct fix. An old restore will not solve a database-server outage and may overwrite newer orders, users, form submissions, or content, so identify the cause before replacing production data.