Back to Community

Troubleshooting the 'Error Establishing a Database Connection' in WordPress

43 threads Sep 7, 2025 CoreLocalhost installs

Content

One of the most common and alarming errors for any WordPress user is the sudden appearance of the "Error establishing a database connection" message. This error completely halts your site, preventing both visitors and you, the administrator, from accessing it. This guide will walk you through what this error means, its common causes, and the steps you can take to resolve it.

What Does This Error Mean?

At its core, this error means that the WordPress software running on your server is unable to communicate with the MySQL or MariaDB database where all your crucial content, settings, and user data is stored. Without this connection, your website cannot function.

Common Causes of the Database Connection Error

Based on community reports and troubleshooting threads, this error typically occurs for one of a few key reasons:

  • Incorrect Database Credentials: The username, password, database name, or host address in your wp-config.php file are wrong. This is the most frequent cause.
  • Database Server Unavailable: The database service on your server (e.g., MySQL) has crashed or is not running.
  • Corrupted Database: The database itself has become corrupted, often due to an incomplete update or a server crash.
  • Server Resource Issues: The server hosting your database has run out of disk space or memory, preventing it from operating correctly.
  • Host-Specific Problems: Your web host may have temporarily suspended your account or is experiencing an outage on their end.

Step-by-Step Troubleshooting Guide

1. Check Your Database Credentials

The first and most important step is to verify the information in your wp-config.php file. You will need to access your site's files using an FTP client, SFTP, or your hosting provider's file manager.

  • Locate the wp-config.php file in the root directory of your WordPress installation.
  • Check the following lines and ensure they exactly match the database connection details provided by your web host:
    define( 'DB_NAME', 'database_name_here' );
    define( 'DB_USER', 'username_here' );
    define( 'DB_PASSWORD', 'password_here' );
    define( 'DB_HOST', 'localhost' ); // (or another host specified by your provider)
  • A single typo here will cause the connection to fail. If you are unsure of the correct credentials, you must contact your web hosting provider's support team to confirm them.

2. Contact Your Web Host

If your credentials are correct, the problem is likely on the server side. Before proceeding with more advanced troubleshooting, it is highly recommended that you contact your hosting provider. They can quickly check:

  • If the MySQL database service is running.
  • If your account is active and not suspended.
  • If the server has enough disk space and memory. An error message containing phrases like "Errcode: 28" or "No space left on device" is a clear indicator of a full disk, which only your host can resolve.
  • If there is a wider server outage affecting your site.

3. Check if the Database Service is Running (For Localhost Users)

If you are running WordPress on a local server stack like XAMPP, WAMP, or Local by Flywheel, the database software (MySQL/MariaDB) may have stopped.

  • Open your local server's control panel (e.g., the XAMPP Control Panel).
  • Ensure that the "MySQL" or "Database" module is started. If it is stopped, try starting it again.

4. Repair a Corrupted Database

WordPress has a built-in feature to attempt to repair a corrupted database. To use it, add the following line to your wp-config.php file:

define( 'WP_ALLOW_REPAIR', true );

After adding this line, visit the following URL in your browser: https://yourdomain.com/wp-admin/maint/repair.php

Important Security Note: Remember to remove this line from your wp-config.php file after you have finished the repair process.

5. Restore from a Backup

If the database is severely corrupted and cannot be repaired, your best course of action is to restore it from a recent backup. Most reputable hosting providers offer regular backups you can restore from their control panel. If you manage your own backups, you can use a tool like phpMyAdmin to import your backup file.

Conclusion

The "Error establishing a database connection" can be stressful, but it is almost always solvable. The process almost always begins with double-checking your wp-config.php credentials and then contacting your web host to investigate server-side issues. For users on localhost, ensuring your database service is running is the key first step.

Related Support Threads Support