How to Fix “Error Establishing a Database Connection” in WordPress

If your WordPress site shows “Error Establishing a Database Connection,” don’t panic. It just means your website can’t talk to the database properly. This is one of the most common WordPress errors.
In this post, you’ll learn what this error means, why it happens, and how to fix it — even if you’re a beginner.
📌 What Does This Error Mean?
WordPress stores everything — your posts, users, settings — in a database. When it can’t connect to that database, it shows this error.
🚨 Common Reasons for the Error
- Wrong database login info
- Database server is down
- Corrupt WordPress files
- Too much traffic crashing the server
- Web hosting issues
🔧 How to Fix “Error Establishing a Database Connection”
Follow this table for step-by-step help:
Step | Action | Why It Helps |
---|---|---|
1 | Check wp-config.php file | Ensures database name, username, and password are correct |
2 | Contact your web host | They can tell you if the database server is down |
3 | Repair the database | Fixes corrupt database tables |
4 | Disable plugins and themes | Rules out plugin or theme issues |
5 | Upgrade your hosting plan | Fixes the error if caused by traffic overload |
🛠️ How to Check Database Settings in wp-config.php
- Connect to your site via FTP or File Manager
- Open the
wp-config.php
file - Look for the following lines:
define('DB_NAME', 'your_database_name'); define('DB_USER', 'your_username'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost');
Make sure they match your hosting database details.
📖 WordPress.org: Editing wp-config.php
🧹 How to Repair the Database
Add this line to your wp-config.php
file just before /* That's all, stop editing! */
:
define('WP_ALLOW_REPAIR', true);
Then visit:
Follow the instructions to repair your database.
🔌 Try Disabling All Plugins
If a plugin is causing the issue:
- Rename the
plugins
folder using FTP or File Manager - This will deactivate all plugins at once
- If your site works again, rename the folder back and activate plugins one by one
🔗 Internal Resources from Gbcodies
- How to Hide WordPress Menu Easily
- Fix WordPress Dashboard Not Loading Properly
- How to Disable Comments in WordPress
🌐 Helpful External Resources
💡 Final Thoughts
Don’t let this error scare you. Most of the time, it’s a small mistake like a wrong password or a busy server. Just go step-by-step, and you’ll be back online soon!