Get 30% off your WordPress Hosting with code WPSAVE10. Launch Faster. Save More!
  • 00 Days
  • 00 Hours
  • 00 Minutes
  • 00 Seconds

WordPress – Error establishing a database connection – Enhance Hosting

Are you encountering the ‘Error establishing a database connection’ message on your WordPress site? This critical error prevents users from accessing your WordPress site.

wp-db-conn-error.png

The ‘Error establishing a database connection’ problem can arise due to incorrect database details in your WordPress settings, a corrupted database, or an unresponsive database server.

WordPress requires the following details to connect to the database:

  • Database name
  • Database username
  • Database password
  • Database host server

These details are stored in your WordPress configuration file, wp-config.php.

Verify your WordPress database credentials

The primary cause of the database connection error in WordPress is usually incorrect database credentials. To resolve this, check the following lines in your wp-config.php file:

/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Confirm your database host server information

If you’re certain that your database name, username, and password are correct, ensure that you’re using the accurate database host information.

We use localhost here at SIRSTEVEHQ

Repair the WordPress database

If you’re encountering a different error in the wp-admin area, such as “One or more database tables are unavailable. The database may need to be repaired,” you’ll need to repair your database.

To do this, add the following line to your wp-config.php file just before the ‘That’s all, stop editing! Happy blogging’ line:

define('WP_ALLOW_REPAIR', true);

After adding this line, visit the following URL to access the repair page: http://www.yoursite.co.uk/wp-admin/maint/repair.php

Once you’ve repaired and optimised your database, remember to remove the added code from your wp-config.php file.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Updating failed. The response is not a valid JSON response – Enhance Hosting

If you cannot save or edit posts or pages and see an error message like “Updating failed. The...

How to Install WordPress Themes

Installing a new WordPress theme allows you to change the appearance and functionality of your...

Optimise WordPress – Enhance Hosting

Optimising a WordPress site involves several strategies that enhance performance, improve loading...

WordPress Site 404 – Enhance Hosting

If immediately after installing WordPress on a site you receive a 404 when using SSO, please...

WordPress toolkit overview – Enhance Hosting

Our Enhance Hosting has a native WordPress manager buit-in. The WordPress toolkit provides a...