Error Establishing Database Connection – WordPress Fix

WordPress “Error Establishing Database Connection” – Fix Now

Last Updated: April 2026 | Skill Level: Intermediate | Affects: All WordPress sites

Is your WordPress site showing “Error establishing a database connection”? This critical error means WordPress can’t communicate with your MySQL database, rendering your entire site inaccessible. While it looks catastrophic, it’s often a simple credential mismatch. Here’s how to restore the connection quickly.

Understanding the Database Connection Error

This error occurs when WordPress (PHP) cannot connect to the MySQL database that stores all your content. Common triggers:

  • Incorrect database credentials in wp-config.php (password changed, username typo)
  • Corrupted database tables (usually after failed updates)
  • Database server downtime (hosting provider maintenance)
  • Exceeded database quota (shared hosting limits reached)
  • Malware injection corrupting connection strings

Fix 1: Verify wp-config.php Credentials (Recommended)

Most cases are simply wrong login details in your configuration file.

Step-by-Step:

  1. Access cPanel > File Manager > public_html (or connect via FTP)
  2. Locate wp-config.php and edit (right-click > Edit)
  3. Verify these 4 lines match your hosting account:
    define('DB_NAME', 'your_database_name');
    define('DB_USER', 'your_username');
    define('DB_PASSWORD', 'your_password');
    define('DB_HOST', 'localhost');
  4. Find correct credentials:
    cPanel: MySQL Databases section (copy exact names)
    Note: DB_HOST is usually ‘localhost’ but some hosts use ‘127.0.0.1’ or specific server names
  5. Update wp-config.php with exact credentials (case-sensitive)
  6. Save and reload site

If credentials are correct but still failing: Try repairing database via cPanel > phpMyAdmin > Select DB > Check All > Repair tables.

✓ Pro Tip: If you recently changed hosting or updated PHP, the DB_HOST might have changed from ‘localhost’ to a specific IP. Check your hosting welcome email for exact connection details.

Fix 2: Contact Hosting Support (Slower)

If credentials are correct and repair fails, the database server may be down or corrupted beyond repair.

Process:

  • Submit ticket: “Database connection error after [recent change]”
  • Request database restart or restore from backup

Timeline: Database restores take 2-24 hours depending on backup size. You’ll lose any content added since the last backup (usually daily backups on good hosts).

⚠️ Warning: Always attempt Fix 1 first. Support will ask you to verify credentials anyway, and if they’re wrong, you’ll wait hours for them to tell you what you could fix in 5 minutes.

Prevention

  • Never edit wp-config.php in WordPress editor—use cPanel File Manager (has syntax backup)
  • Enable automatic database optimization via plugin like WP-Optimize
  • Regular backups via UpdraftPlus or hosting control panel

Bottom Line

Database connection errors look terminal but are usually just wrong passwords. While support can restore backups, checking wp-config.php credentials (Fix 1) resolves 80% of cases immediately. Keep your database credentials documented safely outside WordPress.

Leave a Comment