How to Fix Error Establishing a Database Connection WordPress (Step-by-Step Guide)

The Error establishing a database connection message in WordPress means your website cannot connect to the MySQL database. When this happens, your site stops loading and shows a blank error page.

How to Fix Error Establishing a Database Connection WordPress (Step-by-Step Guide)
How to Fix Error Establishing a Database Connection WordPress (Step-by-Step Guide)

This error usually appears after hosting changes, wrong database settings, plugin problems, or server issues. The good news is that you can fix it by checking a few important settings.

What Causes “Error Establishing a Database Connection” in WordPress

WordPress needs four things to connect to the database:

  • Database name
  • Database username
  • Database password
  • Database host

If any of these values are wrong, WordPress cannot load your site.

Other common causes include:

  • Corrupted database
  • Hosting server problem
  • Plugin crash
  • Database user not assigned
  • Wrong DB_HOST value
  • Too many server requests

Step 1: Check Database Details in wp-config.php

Most database errors happen because of wrong credentials.

Do this

  1. Open your hosting panel
  2. Go to File Manager
  3. Open your WordPress root folder
  4. Find the file
wp-config.php
  1. Open the file and check this section
define('DB_NAME', 'database_name');
define('DB_USER', 'database_user');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', 'localhost');

Make sure these values match your database in hosting.

Check database info in:

  • cPanel → MySQL Databases
  • Hostinger → Databases → MySQL

Save the file and reload your site.

Step 2: Check If Database Exists

Sometimes the database gets deleted or renamed.

Check this

  1. Open hosting panel
  2. Go to MySQL Databases
  3. Look for your database name

If the database is missing, restore backup from hosting.

Step 3: Repair Corrupted Database

If database tables break, WordPress cannot connect.

Enable repair mode

Open wp-config.php and add:

define('WP_ALLOW_REPAIR', true);

Now open:

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

Click:

Repair Database

After repair, remove the line from wp-config.php.

Step 4: Check Database User Permissions

Sometimes the database user does not have permission.

Fix

  1. Open cPanel
  2. Go to MySQL Databases
  3. Scroll to Add User to Database
  4. Select user and database
  5. Click Add
  6. Select ALL PRIVILEGES
  7. Save

Reload your site.

Step 5: Check DB_HOST Value

Some hosts do not use localhost.

Try changing DB_HOST in wp-config.php.

localhost
127.0.0.1
mysql.hostinger.com
db.hostinger.com

Check the correct host in your hosting database page.

Step 6: Disable Plugins (If Error Started After Update)

Plugin crashes can stop database connection.

Fix

  1. Open File Manager
  2. Go to
/wp-content/
  1. Rename folder
plugins → plugins_old

Reload site.

If site works, plugin caused the error.

Rename back and disable plugins one by one.

Step 7: Check Hosting Server Status

Sometimes the problem is not your site.

Database server may be down.

Check:

  • Hosting status page
  • MySQL service
  • Resource limits
  • CPU / RAM usage

Contact hosting support if needed.

Step 8: Check for High Traffic or Resource Limit

On shared hosting, too many requests can stop database.

Fix:

  • Enable cache plugin
  • Use Cloudflare
  • Remove heavy plugins
  • Upgrade hosting plan

The Error establishing a database connection looks serious, but most cases happen because of wrong database settings or server issues.

Always check:

  • wp-config.php credentials
  • Database exists
  • User permissions
  • DB_HOST value
  • Plugins
  • Hosting status

Fixing these usually restores your WordPress site in minutes.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply