You open your website and see one short line: Error Establishing a Database Connection. Your pages are gone, your visitors cannot reach you, and it can feel like the site has been wiped. The good news is that in most cases your content is still safe in the database, and the error can be fixed in a few minutes to an hour once you know where to look.
This guide explains what the error means, why it happens and 10 proven steps to fix it, from checking wp-config.php to repairing the database and restoring a backup.

What does Error Establishing a Database Connection mean?
WordPress stores your posts, pages, settings and users in a database, usually MySQL or MariaDB. Every time someone visits a page, WordPress asks the database for the content. If that request fails, WordPress cannot build the page and shows this error instead. Your files are usually fine, and the problem is the link between WordPress and the database.
Common causes of the error
| Cause | How to recognize it | Typical fix |
|---|---|---|
| Wrong database details | It appears after a migration, a host change or editing wp-config.php | Correct the name, user, password or host |
| Database server down or overloaded | Other sites on the same host may also fail, and the problem may come and go | Contact your host and reduce resource usage |
| Corrupted database tables | The admin area may show a repair message | Repair the database |
| Corrupted core files | It happens after a failed update or upload | Replace the WordPress core files |
| Plugin or theme problem | It begins after installing or updating something | Disable plugins and themes |
| Hosting limits or a full disk | Traffic spikes or storage is full | Upgrade resources or clean up files |
| Hacked site | Credentials changed or unknown files appeared | Clean the site and restore a backup |
Before you start
- Take a backup. Use your hosting panel or a File Manager download. If the database is reachable, export it from phpMyAdmin.
- Get access. You need your hosting control panel, and either FTP or the File Manager, so you can edit files without WordPress.
- Check whether the whole site is down. Visit your home page, an inner page and /wp-admin to see which ones show the error.
How to fix Error Establishing a Database Connection: 10 steps

Step 1: Check whether the error is on the front end, the admin or both
If both the website and /wp-admin show Error Establishing a Database Connection, WordPress cannot connect at all, so continue with the steps below. If the front end shows the error but /wp-admin says that one or more database tables are unavailable, a table is damaged, so jump to Step 6 to repair the database.
Step 2: Check the database details in wp-config.php
The most common cause is a wrong detail in the wp-config.php file, which sits in the main folder of your WordPress installation. Open it with File Manager or FTP and check these four lines:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_password' );
define( 'DB_HOST', 'localhost' );
Compare each value with the database section of your hosting panel. Make sure the user is assigned to the database with full privileges, and check for typos, extra spaces and special characters in the password. Most hosts use localhost as the host, but some use a different server name, so check your host’s documentation. Save the file and reload the site.
Step 3: Test the database connection
Try to log in to phpMyAdmin with the same user and password. If you cannot log in, the credentials are wrong or the user has no access, so reset the database password in your hosting panel and update wp-config.php. If you are comfortable with code, you can also upload a tiny test file that tries to connect with the same details, and delete it right afterwards.
Step 4: Check that the database server is running
If your details are correct and you still see the error, the database server itself may be down or overloaded. Check your host’s status page, and ask support whether the database service is running and whether your account has reached a connection or resource limit. If it works again after a few minutes, a traffic spike or a heavy plugin may be the cause.
Step 5: Check that the database still has your data
Open phpMyAdmin and look at the database named in wp-config.php. You should see tables such as wp_posts and wp_options. If the database is empty or missing, a migration or a reset may have removed it, and you will need to import a backup.
Step 6: Repair the database
WordPress has a built-in repair tool. Add this line to wp-config.php, above the line that says to stop editing:
define( 'WP_ALLOW_REPAIR', true );Then open yourwebsite.com/wp-admin/maint/repair.php and click Repair Database. Remove the line from wp-config.php as soon as you finish, because the repair page can be opened without logging in. You can also repair individual tables from phpMyAdmin.

Step 7: Replace the WordPress core files
Download a fresh copy of WordPress from WordPress.org and upload the wp-admin and wp-includes folders over the existing ones. Do not overwrite wp-content or wp-config.php, because they hold your themes, plugins, uploads and settings. This fixes damaged core files after a failed update.
Step 8: Disable plugins and switch to a default theme
Use FTP or File Manager to rename the plugins folder inside wp-content, for example to plugins-off. If the site connects again, rename the folder back and disable plugins one by one to find the cause. If needed, rename your active theme’s folder so WordPress falls back to a default theme.
Step 9: Check whether your site was hacked
If the details in wp-config.php changed without you touching them, or you see unknown files and users, your site may have been compromised. Change every password, scan for malware and restore a clean backup. Our WordPress security checklist explains exactly how to clean and protect a hacked site.
Step 10: Restore a backup or ask your host for help
If nothing works, restore the most recent clean backup of your files and database from your host or backup plugin. If you have no backup, ask your host to check the server logs. Hosts can often see errors that you cannot, such as a crashed database service or exhausted limits.
How to prevent the error from coming back
- Keep daily backups, with one copy stored offsite, and test a restore.
- Choose reliable hosting with enough resources for your traffic.
- Keep WordPress, plugins and themes updated, and remove those you do not use.
- Optimize your database from time to time and clear old revisions and spam.
- Set up uptime monitoring so you hear about problems before your visitors do.
- Be careful when you edit wp-config.php, and keep a copy of the original.

When to ask an expert for help
Call a professional if you do not have a backup, if your host cannot find the cause, if you suspect a hack, or if the site earns money and every hour of downtime costs you sales. At wpXpart we fix WordPress errors, repair and restore databases, remove malware and set up backups and monitoring. Explore our WordPress maintenance services and security solutions, or hire a WordPress expert.
Frequently asked questions
Did I lose my website content?
Usually not. The content is stored in the database, and the error means WordPress cannot reach it. After you fix the connection or restore a backup, your content normally comes back.
Why did the error appear suddenly?
Common reasons are a database server problem at your host, a traffic spike, a failed update, an edited wp-config.php file, corrupted tables or a hack.
Can a plugin cause this error?
Yes, a badly coded or overloaded plugin can exhaust database connections or damage data. Disable plugins to test.
What is the difference between this error and the white screen of death?
This error is specifically a failed database connection. The white screen of death is a blank page that is usually caused by a PHP error or memory limit, and you can learn how to fix the WordPress white screen of death in our separate guide.
Is it safe to use the WordPress repair tool?
Yes, but take a backup first and remove the repair line from wp-config.php when you finish.
Should I change my database password?
If you suspect a hack or you cannot log in to phpMyAdmin, yes. Update the password in your hosting panel and in wp-config.php at the same time.
How long does it take to fix?
Simple causes such as a wrong password take minutes. Server problems depend on your host, and restoring a large site from a backup can take longer.
How can I stop it from happening again?
Use reliable hosting, keep tested backups, update and clean up your plugins, and monitor your uptime.
Related guides
Keep learning with these step-by-step guides from our team.
- WordPress Security Checklist: 20 Steps: protect your site from hackers.
- How to Improve Core Web Vitals on WordPress: fix LCP, INP and CLS.
- How to Connect AI Agents to WordPress Using MCP: let AI agents work safely on your site.
- How to Fix the WordPress Internal Server Error: solve the 500 error.
- How to Fix WordPress Stuck in Maintenance Mode: delete the .maintenance file.
- How to Fix Too Many Redirects in WordPress: break the redirect loop.
- How to Fix WordPress Login Page Refreshing: stop the login loop.
Conclusion
To fix Error Establishing a Database Connection, stay calm, take a backup and work through the checks in order: wp-config.php, the connection test, the database server, a repair, fresh core files, plugins, hack checks and finally a backup restore. Most sites are back online quickly, and good backups and reliable hosting keep the next incident small.
Stuck on this error? Start a project with wpXpart and we will get your WordPress site back online.
Need help with your WordPress site?
Tell us about your project and get a clear, written proposal.
Stay tuned with our latest updates
Subscribe for practical WordPress tips and news.






















