How to Fix WordPress Error Establishing a Database Connection?

how to fix wordpress error establishing a database connection featured image

WordPress website uses MySQL database to store and output data in your frontend. Having this error “WordPress Error Establishing A Database Connection” means you are not able to connect to the database or the database is not configured well.

The “Error Establishing A Database Connection” error occurs when your database information (Database Name, Database Username, Database Password, and Database Server) is incorrect. It is possible also that the database got corrupted or the database hosting server is down.

In this guide, we will teach you how to fix this error.

Check Your Database Credentials

The first thing to check is looking at the database configuration that can be found in wp-config.php. This is where you put the correct database information mentioned above.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database name here' );

/** MySQL database username */
define( 'DB_USER', 'database username here' );

/** MySQL database password */
define( 'DB_PASSWORD', 'database password here' );

/** MySQL hostname */
define( 'DB_HOST', 'database server here' );

Make sure that the credentials are correct by checking your website hosting dashboard.

Simply find the MySQL Databases settings, and you can see all the information there.

how to fix wordpress error establishing a database connection manage database

Once you checked and updated your database information, try to reload the website if the error has been corrected.

Try to Repair your WordPress Database

If the error is still there or WordPress is asking you to repair the database, here’s how to fix it.

Just copy the code below to your wp-config.php file. Make sure to add it below this line “/* Add any custom values between this line and the “stop editing” line. */”.

define('WP_ALLOW_REPAIR', true);

how to fix wordpress error establishing a database connection database repair script

Once it is done saving, try to visit your website with this URL format “”.

how to fix wordpress error establishing a database connection database repair page

You just have to choose either you only want to Repair Database or Repair and Optimize Database.

After the repair, make sure to remove that line of code you added because it will still work even if there is no user session logged in to your website.

Contact Hosting Provider

If your problem still did not fix, try to contact your hosting provider if there is any problem with their servers or just let them reboot your web server.

Wrapping Up

I hope that this article helped you in fixing your WordPress database and make it run smoother and faster.

Leave a Comment

Scroll to Top