How to Fix “Error Establishing Database Connection”

  • Last Created On Jul 06, 2025
  • 32
1 0
Fix: Error Establishing Database Connection

How to Fix: "Error Establishing Database Connection"

This error appears when WordPress can't communicate with your database. Here’s how to fix it step-by-step:

✅ Common Causes:

  • Incorrect database credentials
  • Corrupt WordPress files or database
  • Database server down
  • Too many simultaneous connections
  • Hosting issues

🔧 Step-by-Step Fix

1. Check wp-config.php File

Open your wp-config.php file and verify these lines:

define('DB_NAME', 'your_db_name');
define('DB_USER', 'your_db_user');
define('DB_PASSWORD', 'your_db_password');
define('DB_HOST', 'localhost');
Tip: Get these values from your hosting control panel.

2. Check Database Server (DB_HOST)

Some hosts use an IP or custom URL instead of localhost. Contact your host if unsure.

3. Repair the Database

Add this line to wp-config.php before /* That's all, stop editing! */:

define('WP_ALLOW_REPAIR', true);

Then visit: http://yourdomain.com/wp-admin/maint/repair.php

Click on Repair Database or Repair and Optimize Database, then remove the line.

4. Test DB Connection with PHP

Create a file testdb.php in your root folder:

<?php
$mysqli = new mysqli('localhost', 'db_user', 'db_password', 'db_name');
if ($mysqli->connect_error) {
    die('Connect Error: ' . $mysqli->connect_error);
} else {
    echo 'Connection successful!';
}
?>

Visit http://yourdomain.com/testdb.php to test.

5. Check for Corrupt Files

Re-upload fresh wp-admin and wp-includes folders from a clean WordPress package. Do not overwrite wp-content.

6. Hosting or MySQL Server Down

Ask your hosting provider: “Is the MySQL server currently running and accepting connections?”

7. Disable Plugins

Rename /wp-content/plugins/ to /plugins_old/ to disable all plugins temporarily.

8. Enable WP_DEBUG

In wp-config.php, enable debug mode:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Check /wp-content/debug.log for details.

🚀 Optional Tips

  • Upgrade PHP and MySQL to the latest stable versions
  • Use caching plugins to reduce database load

Still need help? Create a technical support ticket, Back2cloud will fix it for you!.

Views: 32

Recent Articles

  • How to Fix “Error Establishing Database...
    32

Popular Articles

  • How to Fix “Error Establishing Database...
    32
!-- Floating WhatsApp Button --> WhatsApp Chat