How to rectify “Error Establishing A Database Connection” in WordPress

When you receive Error Establishing A Database Connection in your website, make sure if this error is also in the backend. For that, you should check the Wp-admin dashboard.

If you find a similar exact message after accessing the wp-admin dashboard, then skip and go to the next step, because you have already detected the potential reason for this error

If you find different notification saying, “The database needs repair”, then read this section and understand how to repair your Error Establishing A Database Connection in WordPress.


Step 1: Check wp-config.php file for repair 

  • Edit wp-config.php file by connecting through FTP client or C-panel
  • Go to File Manager tool
  • Locate the wp-config.php file. At the root folder of your WordPress site.
  • After you can edit your wp-config.php file, you need to put this syntax bottom of the file
  • define( ‘WP_ALLOW_REPAIR’, true );
  • Save changes before continuing
  • Step 2 Go for automated database repair service
  • After you add the syntax, you can access the database repair tool by navigating to
  • is an example)
  • On that page click Repair Database and it starts repairing
  • Repairing of WordPress Database

After the tool finishes its repair process, we assume your website get back to the normal. If it does the same, you require going back to the wp-config.php file and deleting the same syntax, which you have put to allow the repair process.

If your website is still not functioning, try the next process.

Step 2 verify your Database Login credentials. 

  • If you find that your Database is not damaged, the following process, you should verify whether your database login credentials are correct or not.
  • The database credentials are present in your wp-config.php file
  • If the database credentials are not correct or mismatched that you generated through your host dashboard, then WordPress cannot access Database.
  • To inspect if your database credentials are functioning, you can utilize the mysql_connect() function.
  • You can use a text editor like Edit+, dream-viewer, or Notepad to generate a file named databasecheck.php.

Then write the syntax.


$link = mysql_connect(‘localhost’, ‘mysql_user’, ‘mysql_password’);

if (!$link) {

die(‘Could not connect: ‘ . mysql_error());


echo ‘Connected successfully’;



Ensure that to swap mysql_user” and “mysql_password with the authentic username and password through wp-config.php file.

After that, upload that file to your WordPress website through FTP ort Cpanel by navigating this is an example)

If you find the alert that tells “Connected successfully,” it means your database credentials are functioning, and then you can bounce to the next process  

However if you a message that pops up in your website below, then you have an issue with your database credentials

Access denied for user ‘root’ @ ‘localhost.’

The simplest method to rectify this issue is to generate a new set of database credentials so that you can use it for your website.

Let’s take a look at these steps to create a new set of database credentials.

  • 1: Navigate to MySQL Databases in cPanel
  • You can generate a new database user by navigating to the MySQL Databases in your Cpanel dashboard.
  • 2: Make a new user.
  • Roll down to the MySQL user’s location and search the box to Add a New User.  
  • Scroll down to the MySQL Users area and find the box to add a New User.
  • Fill these details:
  • Username
  • Password
  • MySQL Users

Ensure to memorize these credentials as you require them in a while  

Step 3: Update your wp-config.php file with new database user

  • To complete the process, you must return to the wp-config.php file and update the DB_PASSWORD field and DB_USER to the new user
  • After you save the changes, we assume that your Site is functioning again

Step 4: Re-upload your WordPress Core Files 

  • If above methods doesnt solve the error, then a few of your WordPress core files might be damaged or corrupted.
  • Make sure, and if it is the issue, then you can upload a new copy of the WordPress file to your Site. Don’t worry as this doesnt not hinder any of your already available themes, content, and plugins.  
  • Navigate to and install the newest version of WordPress:
  • Remove the wp-config-sample.php file and wp-content folder
  • Upload the rest of the files to your WordPress website through FTP. The FTP asks what action needs to do for duplicate files, ensure to select the choice to Overwrite duplicate files.
  • This makes sure that your core WordPress files not corrupted, and it solves issue optimistically.

Wrap up 

At the end of these steps, we can only assume that you can fix the error establishing a database connection. However, if the problem continues, then interaction with authorized WordPress people is recommended.  

Leave a Reply

Your email address will not be published. Required fields are marked *