Register Now & Download Free 5,000+ Premium WordPress themes and plugins.

How to Fix the “Error Establishing a Database Connection” in WordPress (Step-by-Step Guide)

What Does “Error Establishing a Database Connection” Mean?

This error occurs when WordPress is unable to connect to the database that stores all your site’s content and settings. The site files (themes, plugins, etc.) are still there, but WordPress can’t fetch data like posts, pages, and user information because the database connection is broken.

This issue can stem from:

  • Incorrect database credentials
  • A corrupt database
  • Unresponsive database server
  • Too many concurrent connections
  • Web host issues

Let’s troubleshoot each cause systematically.


1. Check Your wp-config.php File

The wp-config.php file holds the database connection details. Even a small typo here can break your site.

Steps:

  • Connect to your website via FTP or use your hosting file manager.
  • Open wp-config.php.
  • Look for these lines:
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');

Make sure:

  • DB_NAME matches your database name.
  • DB_USER and DB_PASSWORD are correct.
  • DB_HOST is usually localhost, but some hosts use a different hostname.

Double-check with your hosting control panel if you’re unsure.


2. Test Database Connection Manually

To see if the issue is truly with credentials or the server, create a simple test script.

Create a file named dbtest.php and upload it to your site’s root folder:

<?php
$link = mysqli_connect("localhost", "your_username", "your_password", "your_database_name");
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully!";
?>

Visit yourdomain.com/dbtest.php. If it fails to connect, your credentials or server are the problem.


3. Repair Your WordPress Database

A corrupt database can also trigger the error.

How to fix:

  • Add this line to your wp-config.php:
phpCopyEditdefine('WP_ALLOW_REPAIR', true);
  • Visit: yourdomain.com/wp-admin/maint/repair.php
  • Choose “Repair Database” or “Repair and Optimize Database”

Once done, remove that line from wp-config.php to secure your site.


4. Check with Your Web Host

If the above steps check out, your database server might be down or overloaded. Contact your hosting provider and ask:

  • If your database server is running.
  • If there’s a cap on concurrent database connections.
  • If there are any server-side issues causing downtime.

Upgrading to a better hosting plan or switching to a managed WordPress host can prevent this in the future.


5. Restore a Backup (Last Resort)

If nothing works and your site was running fine recently, restore a backup of your database and files. This is why automated backups are critical for every WordPress site.

Leave a Reply

Your email address will not be published. Required fields are marked *

16873 Happy Customers😀

100% Genuine – All Premium Features Unlocked.
We source and download directly from the original developers to ensure you receive the most authentic and up-to-date version.


Safe & Secure
The file is scanned daily by Norton and McAfee, ensuring it is 100% free of viruses, malware, and harmful scripts. Feel free to run your own online security check using the button below the product image.


Unlimited Site & Domain Usage
The file can be utilized on unlimited sites, fully compliant with WordPress’s GPL licensing policies.


7 days money back guarantee

  1. Safe & Secure Downloads
    Every file is scanned daily by top antivirus programs like Norton and McAfee, ensuring 100% virus-free, malware-free, and secure downloads. You can also run your own security check for added confidence.
  2. Unlimited Usage
    Use our GPL-licensed themes and plugins on unlimited websites and domains. Perfect for single sites or multi-domain setups, our products offer unmatched flexibility.
  3. 6 Months of Free Updates
    Stay up-to-date with 6 months of free updates. Get notified instantly when new versions are released, and download links are sent directly to your email. Keep your site secure, functional, and compatible with the latest WordPress updates.
  4. Why So Affordable?
    WordPress’s GPL/GNU license allows us to purchase products directly from developers and redistribute them at low costs. Enjoy premium features with a one-time payment—no recurring fees. (Note: Original author support is not included.)

 

My Cart
Recently Viewed
Categories