Offer Shared Hosting Ultra-fast Performance! 29$ using coupon new-2026 1st/y

Claim Offer
Print

How to Fix the "Error Establishing a Database Connection" in WordPress

Database Connection Error

This WordPress-specific error means the site cannot communicate with its MySQL database.

Common Causes

  • Wrong database credentials in wp-config.php
  • Corrupted database
  • Database server down
  • Exceeded database limits

How to Fix

1. Verify wp-config.php Credentials

Open wp-config.php and check:

define('DB_NAME', 'your_database_name');\ndefine('DB_USER', 'your_database_user');\ndefine('DB_PASSWORD', 'your_password');\ndefine('DB_HOST', 'localhost');

Ensure these match your cPanel MySQL database settings.

2. Test Database Connection

Create a test file testdb.php:

<?php\n$conn = mysqli_connect('localhost', 'user', 'pass', 'dbname');\nif (!$conn) die('Failed: ' . mysqli_connect_error());\necho 'Connected!';\n?>

Delete this file after testing.

3. Repair Database

Add to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Visit yourdomain.com/wp-admin/maint/repair.php. Remove the line after repair.

4. Check Disk Quota

If your hosting account is out of disk space, the database cannot write. Free up space or upgrade your plan.

Was this answer helpful?

Your feedback helps us improve our content