Skip to main content

How to Fix the WordPress “Error Establishing a Database Connection” Message

The "Error Establishing a Database Connection" message indicates that your WordPress site cannot communicate with the MySQL or MariaDB database. This issue typically occurs due to incorrect database credentials, a failed database server, or a...

The "Error Establishing a Database Connection" message indicates that your WordPress site cannot communicate with the MySQL or MariaDB database. This issue typically occurs due to incorrect database credentials, a failed database server, or a corrupted database table.

Before you begin

You will need:

  • Site Administrator access to the WordPress dashboard (if available) or access to your hosting control panel.

  • Access to the wp-config.php file via a File Manager or FTP client.

  • Access to a database management tool, such as phpMyAdmin.

Check your database credentials

Most connection errors are caused by incorrect information in the WordPress configuration file.

  1. Access your site's root directory using a File Manager or FTP client.

  2. Locate and open the wp-config.php file.

  3. Locate the following lines:

    define( 'DB_NAME', 'database_name' );
    define( 'DB_USER', 'username' );
    define( 'DB_PASSWORD', 'password' );
    define( 'DB_HOST', 'localhost' );

  4. Verify that the values for DB_NAME, DB_USER, and DB_PASSWORD match the credentials provided in your hosting control panel.

  5. If the values are incorrect, update them to the correct credentials and save the file.

Check the database server status

If the credentials are correct but the connection still fails, the database server may be offline or overwhelmed.

  1. Log in to your hosting control panel.

  2. Navigate to the database management section (e.g., MySQL Management).

  3. Verify that the database server is running and that your specific database is active.

  4. If the server is down, contact Hostek support to investigate the service status.

Repair a corrupted database table

A corrupted table can prevent WordPress from establishing a connection.

  1. Open your wp-config.php file.

  2. Add the following line just before the "That's all, stop editing!" message:

    define( 'WP_ALLOW_REPAIR', true );

  3. Open your web browser and navigate to the following URL: http://example.com/wp-cron.php?_doing_cron=false (Replace example.com with your actual domain).

  4. If the repair is successful, you will see a message stating that the database has been repaired.

  5. Warning: Once the repair is complete, remove the define( 'WP_ALLOW_REPAIR', true ); line from your wp-config.php file to ensure the site remains secure.

How to Fix a "Database Connection Error" via phpMyAdmin

If you can access your control panel but cannot access the WordPress dashboard, you can check the database status directly.

  1. Log in to your hosting control panel.

  2. Open phpMyAdmin.

  3. Select your database from the list on the left.

  4. Click the Check or Repair option under the "Operations" or "SQL" tab for your tables.

  5. If the table is repaired, the connection should be restored.

Confirm the result

  • Your WordPress site loads successfully.

  • The "Error Establishing a Database Connection" message no longer appears.

Limitations

This procedure does not resolve issues caused by local network failures or firewall blocks on your specific IP address. If you have confirmed your credentials and the server is active but still cannot connect, contact Hostek support to check for IP-specific blocks.

Did this answer your question?