HostPro
← Back to Knowledge Base
WordPress Guides

Fixing "Error Establishing a Database Connection"

This error occurs when WordPress cannot connect to its database. Follow these steps to fix it:

  1. Check wp-config.php: Login to cPanel > File Manager and find wp-config.php in your site root.
  2. Verify that DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST are correct.
  3. Verify Database User: In cPanel > MySQL Databases, ensure the user is added to the database with "All Privileges".
  4. Check Database Corruption: Add define('WP_ALLOW_REPAIR', true); to wp-config.php, then visit yourdomain.com/wp-admin/maint/repair.php.

Don't forget to remove the repair line from wp-config.php after you're done!

Was this article helpful?