9:00 AM - 22:00 PM
Seeing “Error establishing a database connection” in WordPress can be alarming—it halts your site, frustrates users, and hurts credibility. Fortunately, it’s usually fixable. This guide explains what causes the error and walks you through simple, step-by-step solutions for getting your site back online—whether you’re a beginner or a seasoned WordPress user.
When WordPress displays “Error establishing a database connection”, it means your site can’t communicate with the MySQL database that stores content, settings, user information, and more.
If WordPress can’t access the database, it can’t render your site. What’s worse, the error offers no detail about what went wrong, making it more frustrating than helpful. That’s why understanding the possible causes is essential.
This is the most common reason. WordPress needs four pieces of information to connect to your database:
If any of these values in your wp-config.php
file are wrong, the connection will fail.
Sometimes, corrupted core files, themes, or plugins can prevent WordPress from connecting properly. A failed update or file system issue often causes this.
Even if your credentials are correct, the server hosting your database may crash or become unresponsive due to overload or technical issues.
A sudden spike in traffic—especially on shared hosting—can overwhelm your server and trigger a connection error. This is a good problem to have, but you’ll still need to fix it fast.
Let’s move on to practical solutions.
Your wp-config.php
file contains the database login credentials. Use FTP or your hosting control panel to access this file.
Make sure the following lines are correct:
define( ‘DB_NAME’, ‘your_database_name’ );
define( ‘DB_USER’, ‘your_database_username’ );
define( ‘DB_PASSWORD’, ‘your_database_password’ );
define( ‘DB_HOST’, ‘localhost’ ); // Sometimes ‘127.0.0.1’ or a custom hostname is used
If you’re unsure, confirm the correct values in your hosting control panel (like cPanel → MySQL Databases).
✅ If you just migrated your site, make sure these credentials reflect the new environment.
Sometimes, your database becomes corrupted.
To fix it:
wp-config.php
file again.define(‘WP_ALLOW_REPAIR’, true);
3.Visit:
yourdomain.com/wp-admin/maint/repair.php
Once finished, remove the line from wp-config.php
to secure your site.
Use your hosting dashboard or contact support to confirm:
If you have SSH access, you can run:
service mysql status
or check with:
top
to inspect resource usage.
Alternatively, switch to a more robust host if your site outgrows shared hosting.
If your database or WordPress files are beyond repair, restoring a previous working version might be the quickest fix.
Use your hosting provider’s backup tool or a plugin like UpdraftPlus or BlogVault.
⚠️ Make sure to restore both the files and the database.
Add this to wp-config.php
to see more detailed error messages:
define( ‘WP_DEBUG’, true );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
Then check the log in /wp-content/debug.log
.
Low PHP memory can cause server-side issues. Increase it by editing wp-config.php
:
define( ‘WP_MEMORY_LIMIT’, ‘256M’ );
Corrupt plugins can cause connection issues. Use FTP or file manager to rename the wp-content/plugins
folder to something like plugins_old
. This disables all plugins.
Check your site. If it loads, rename the folder back and activate plugins one by one to find the culprit.
The “Error establishing a database connection” in WordPress may look intimidating, but you can fix it efficiently with a logical approach. Start by verifying credentials, then explore database integrity and server responsiveness.
Remember, regular backups, solid hosting, and optimized databases reduce the risk of this error happening again.
If you’re managing a business website, every second of downtime matters. Don’t just fix—optimize and prepare. And if you want expert help building a site that not only performs but converts, our team at AIRSANG DESIGN is ready to craft custom WordPress solutions tailored to your business goals.
Copyright © 2025 AIRSANG. All rights reserved.