Fix WordPress Database Connection Error

Error establishing database connection is a common WordPress issue. Here is how to resolve it.

What Causes This Error?

  • Incorrect database credentials
  • Database server down
  • Corrupted database
  • Database host change

Solution 1: Check Database Credentials

  1. Open wp-config.php via FTP
  2. Verify these values:
define('DB_NAME', 'database_name');ndefine('DB_USER', 'database_user');ndefine('DB_PASSWORD', 'password');ndefine('DB_HOST', 'localhost');

Finding Correct Values

  1. Log into cPanel
  2. Go to MySQL Databases
  3. Check database name
  4. Verify username
  5. Reset password if needed

Solution 2: Check Database Host

Common values:

  • localhost (most common)
  • 127.0.0.1
  • Specific IP from host

Contact hosting if unsure.

Solution 3: Repair Database

Add to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Visit: yourdomain.com/wp-admin/maint/repair.php

Remove code after repair!

Solution 4: Check Database Server

  1. Log into cPanel
  2. Access phpMyAdmin
  3. If it loads, database is running
  4. If not, contact hosting support

Solution 5: Restore from Backup

  1. Access latest backup
  2. Restore database via phpMyAdmin
  3. Import .sql file

Solution 6: Check Privileges

  1. Go to MySQL Databases in cPanel
  2. Verify user has ALL PRIVILEGES
  3. Add user to database again if needed

Final mention: Please feel free to contact us for database troubleshooting.

Similar Posts

Leave a Reply

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