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.phpfile 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.
Access your site's root directory using a File Manager or FTP client.
Locate and open the
wp-config.phpfile.Locate the following lines:
define( 'DB_NAME', 'database_name' ); define( 'DB_USER', 'username' ); define( 'DB_PASSWORD', 'password' ); define( 'DB_HOST', 'localhost' );
Verify that the values for
DB_NAME,DB_USER, andDB_PASSWORDmatch the credentials provided in your hosting control panel.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.
Log in to your hosting control panel.
Navigate to the database management section (e.g., MySQL Management).
Verify that the database server is running and that your specific database is active.
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.
Open your
wp-config.phpfile.Add the following line just before the "That's all, stop editing!" message:
define( 'WP_ALLOW_REPAIR', true );
Open your web browser and navigate to the following URL:
http://example.com/wp-cron.php?_doing_cron=false(Replaceexample.comwith your actual domain).If the repair is successful, you will see a message stating that the database has been repaired.
Warning: Once the repair is complete, remove the
define( 'WP_ALLOW_REPAIR', true );line from yourwp-config.phpfile 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.
Log in to your hosting control panel.
Open phpMyAdmin.
Select your database from the list on the left.
Click the Check or Repair option under the "Operations" or "SQL" tab for your tables.
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.
