How to fix ‘Error establishing database connection’ on your WordPress website?

While this article is a guide on fixing database connection errors on WordPress, if you’d like to build a mobile app for your WordPress website, get started here.

Website errors can appear at the worst times, and few are more frustrating than the “Error establishing database connection” message on a WordPress site. This common issue means your website can’t access the database that stores all your content, users, and settings. The result is downtime, lost visitors, and potential damage to your brand reputation.

Fortunately, this problem is solvable. In this updated 2025 guide, we’ll walk you through the most effective ways to diagnose and fix this error, ensuring your website — and any connected mobile app — stays online and functional.

If you’re using AppMySite to turn your WordPress site into a mobile app, maintaining high uptime ensures your app continues to perform smoothly. And even if you don’t have a website, AppMySite also enables you to build powerful apps from scratch — no code, no WordPress required.

Let’s get started.

Read: Common WordPress errors that can crash your website

What causes the database connection error in WordPress

Your website’s database is where all its content, pages, users, and configurations are stored. WordPress connects to it every time a visitor lands on your site. When this connection fails, WordPress can’t retrieve the necessary data, and you see the dreaded “Error establishing database connection” screen.

Common causes include:

  • Incorrect database credentials in the wp-config file
  • Database server overload or downtime
  • Corrupted database tables
  • Incorrect file or directory permissions
  • Misconfigured plugins or caching issues
  • Problems with your hosting provider

The steps below will help you identify and fix the problem.

1. Clear your website and browser cache

Sometimes the error isn’t as severe as it looks. Your browser or caching plugin may have stored an outdated version of your website, showing the error page even after the issue is resolved.

Here’s what to do:

  1. Clear your browser cache and cookies.
  2. If you use a caching plugin (like WP Rocket or W3 Total Cache), purge the cache.
  3. Wait a few minutes and reload your website.

If the error disappears, your database connection is fine. However, if the error persists, continue to the next step.

Pro tip: Use a reliable hosting service that handles caching efficiently to minimize such issues.

2. Verify your wp-config.php file

One of the most common causes of this error is incorrect database credentials. These credentials are stored in your wp-config.php file, located in the root directory of your WordPress installation.

To check:

  1. Log in to your website’s hosting panel or connect via FTP.
  2. Locate and open the wp-config.php file.
  3. Look for the following lines:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'username' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );

Ensure these values match the credentials listed in your hosting panel. If they don’t, update them and re-upload the file. Always keep a backup of wp-config.php before making any edits.

If your credentials are correct but the issue remains, move on.

3. Check if your database server is down

Your database server might be temporarily unavailable due to high traffic, plugin overload, or limited server resources.

To check:

  • Contact your hosting provider’s support team and ask if the MySQL server is down.
  • If you use a self-managed server, connect via an SSH client like PuTTY and run the following command:
sudo netstat -plt

If you don’t see MySQL or MariaDB listed, your database service isn’t running. Start it manually with:

sudo systemctl start mysql

After this, re-run the netstat command to confirm that MySQL is active. If it is, refresh your website to check if it’s working again.

4. Repair your WordPress database

WordPress includes a built-in repair tool that can help fix corrupted database tables.

To use it:

  1. Open your wp-config.php file.
  2. Add this line just above “That’s all, stop editing! Happy blogging.”:
define('WP_ALLOW_REPAIR', true);
  1. Go to:
https://yourwebsite.com/wp-admin/maint/repair.php
  1. Click Repair and Optimize Database.

Once the repair is complete, remove the line you added to the wp-config.php file to prevent unauthorized access.

This feature is also helpful when facing similar issues like the “White Screen of Death.”

5. Verify file and directory permissions

Incorrect file permissions can block WordPress from reading or writing necessary data, which may trigger a connection error.

Typically, WordPress recommends:

  • Files: 644 or 640
  • Directories: 755 or 750

You can adjust permissions via your FTP client or hosting file manager. If you’re unsure, contact your hosting provider — most managed WordPress hosts can fix this quickly.

6. Contact your hosting provider

If all else fails, it’s time to reach out to your hosting support. Hosting providers can check server-level issues, database corruption, or account suspensions that may be affecting connectivity.

Managed WordPress hosts often include proactive monitoring, backups, and automatic database recovery — which means faster resolutions and less downtime.

If you’re facing frequent errors, consider upgrading your hosting plan or migrating to a host that specializes in WordPress performance.

How to prevent future database connection errors

Once you’ve fixed the issue, follow these best practices to prevent it from happening again:

  • Regularly back up your database and files.
  • Avoid installing unnecessary plugins.
  • Monitor your website uptime with tools like UptimeRobot or Jetpack.
  • Keep your WordPress core, themes, and plugins updated.
  • Use a reputable managed hosting provider.

Maintaining a stable database is essential not just for your website but also for your app if you’ve connected it to AppMySite. Consistent uptime ensures your mobile app continues working seamlessly.

Final thoughts

The “Error establishing database connection” message can bring your WordPress site to a halt, but with a structured troubleshooting approach, you can resolve it quickly. By checking credentials, repairing your database, and maintaining good hosting hygiene, you can minimize future downtime.

If you’re building or maintaining an app connected to your website, uptime directly impacts user experience. And if you’d rather skip the website complexities altogether, AppMySite enables you to build and launch mobile apps — even without a website — in just a few clicks.

Create your app today and keep your business always within reach.

SIMILAR

Related Articles