WordPress error establishing a database connection

How to Fix Error Establishing a Database Connection in WordPress

The Error establishing a database connection message means WordPress cannot communicate with the database containing your website’s content, settings, users, and other important information.

The most common causes are incorrect database credentials, a database server outage, database corruption, or a hosting resource problem. Follow these steps in order, starting with the safest fix.

1. Check Whether Your Hosting Provider Is Having Problems

Before editing any files, check your hosting provider’s status page or contact support. If the database server is unavailable, you cannot fix the problem from inside WordPress.

Ask your host:

  • Is the MySQL or MariaDB server running?
  • Is my account exceeding its database or resource limits?
  • Were any database credentials recently changed?
  • Can you confirm that my WordPress database is accessible?

If multiple websites on the same hosting account are showing database errors, the hosting environment is the most likely cause.

2. Confirm Your WordPress Database Credentials

WordPress stores its database connection information inside the wp-config.php file. You can access this file using your host’s file manager, cPanel File Manager, SFTP, or FTP.

Look for these four settings:

define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_username' );
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'localhost' );

Compare them with the database information shown in your hosting account. According to the official WordPress wp-config.php documentation, this file contains the base configuration details WordPress uses to connect to its database.

Do not copy your real database password into an email, support forum, screenshot, or public document.

3. Reset the Database User Password

If the database name and username are correct, the password may have been changed or corrupted during a migration, hosting move, or security cleanup.

  1. Create a current website backup if your hosting account allows it.
  2. Open the database management section of your hosting account.
  3. Reset the password for the database user assigned to the website.
  4. Update the DB_PASSWORD value inside wp-config.php.
  5. Save the file and reload the website.

A single incorrect character will prevent WordPress from connecting.

4. Check the Database Host

Many WordPress installations use localhost as the database host, but that is not universal. Some hosting providers use a separate hostname, IP address, socket, or database server address.

Do not automatically replace the existing value with localhost. Confirm the correct database host with your provider first.

5. Repair a Corrupted WordPress Database

If the credentials are correct and the database server is running, one or more database tables may be damaged.

Create a backup before attempting a repair. Then add the following line to wp-config.php above the line that says to stop editing:

define( 'WP_ALLOW_REPAIR', true );

Visit:

https://example.com/wp-admin/maint/repair.php

Replace example.com with your domain. Choose either:

  • Repair Database
  • Repair and Optimize Database

Once the repair finishes, immediately remove the WP_ALLOW_REPAIR line from wp-config.php. The repair page does not require a WordPress login while this setting is enabled.

6. Restore a Known Working Backup

If the error started after a migration, database import, malware cleanup, or major website change, restoring a recent working backup may be the fastest recovery option.

Make sure the backup includes both:

  • The WordPress files
  • The WordPress database

Restoring only the files will not repair a missing or damaged database.

7. Escalate the Problem to Your Host or Developer

Stop making changes if you cannot identify the correct database, database user, or backup. Guessing inside wp-config.php can make recovery harder.

Your hosting provider or WordPress developer should check:

  • Database server availability
  • Database user permissions
  • Corrupted or missing database tables
  • Storage and resource limits
  • Recent server, DNS, or migration changes
  • Signs of malware or unauthorized changes

Can a Plugin Cause a Database Connection Error?

Usually, no. WordPress must connect to the database before most normal plugin functions can run. However, a poorly coded plugin, excessive database activity, a broken caching layer, or a resource-intensive process can contribute to database instability.

Removing random plugins should not be your first troubleshooting step.

Can This Error Affect SEO?

Yes. While the database is unavailable, visitors and search engines cannot access the affected pages. A short outage is unlikely to cause lasting damage, but repeated or extended outages can interfere with crawling, indexing, user experience, and conversions.

After restoring the website, confirm that important pages return a successful 200 status code and review Google Search Console for new server errors.

Preventing Future Database Connection Problems

  • Maintain automatic daily backups.
  • Keep WordPress, themes, and plugins updated.
  • Remove unnecessary plugins and abandoned software.
  • Monitor hosting storage and resource usage.
  • Use staging before major migrations or database changes.
  • Document database changes and website maintenance.

Regular WordPress website maintenance makes database problems easier to identify and recover from.

Need Help Recovering Your WordPress Website?

If your website is offline and you are not comfortable editing configuration files or repairing the database, stop before making additional changes.

Contact me for WordPress troubleshooting and recovery help.

Published by
JL Faverio

JL Faverio is a Technical SEO Consultant specializing in WordPress, technical SEO, and website maintenance. I help businesses and agencies fix technical SEO issues, maintain WordPress websites, improve site speed, and solve problems that other developers can't. With years of experience managing hundreds of WordPress websites, I focus on practical solutions that improve search visibility and long-term website health.