"Error Establishing a Database Connection" in WordPress

Updated 3 hours ago 8 views

Quick Summary

This error means your website code cannot communicate with your MySQL or MariaDB database. It is typically caused by incorrect database login credentials in your configuration file, corrupted database tables, or exhausted database user privileges.

Common Causes & Step-by-Step Fixes

1. Verify Credentials in wp-config.php

The most common cause of a database connection error is a mismatch between your database credentials and what WordPress expects.

  1. Log into your hosting control panel and open the File Manager.

  2. Navigate to your site's root directory (public_html).

  3. Edit the wp-config.php file and locate the following lines:

    define( 'DB_NAME', 'your_database_name' ); define( 'DB_USER', 'your_database_user' ); define( 'DB_PASSWORD', 'your_database_password' ); define( 'DB_HOST', 'localhost' );

  4. Verify that DB_NAME, DB_USER, and DB_PASSWORD match the active database and user created on your hosting server.

2. Verify Database User Permissions

Even if the username and password are correct, the database user must have full privileges assigned to that specific database.

  1. Open MySQL Databases in your control panel.
  2. Scroll to the Add User to Database section.
  3. Ensure your database user is assigned to the correct database with ALL PRIVILEGES granted.

3. Repair a Corrupted Database Table

If your credentials are correct, a database table may have become corrupted during a plugin update or unexpected site crash.

  1. Open wp-config.php in your File Manager.

  2. Add the following line just above /* That's all, stop editing! Happy publishing. */:

    define( 'WP_ALLOW_REPAIR', true );

  3. Save the file and visit [https://yourdomain.com/wp-admin/maint/repair.php](https://yourdomain.com/wp-admin/maint/repair.php) in your browser.

  4. Click Repair Database.

  5. Important: Once repaired, remove that line from wp-config.php to secure your application.

Still Having Issues?

  • Hosting Support: If you are hosted on GaugeHosting.com, open a ticket under Support in your client portal so our technical engineers can check database service availability and server health.
  • Custom Development & Site Repair: If you need hands-on assistance repairing custom code, broken WordPress installations, or ongoing site maintenance, contact the web development team at Horizon Web Services for dedicated technical management.

Still need help?

If this article did not answer your question, our support team can help.
Top