Error Establishing A Database Connection in WordPress” is  an entirely typical problem encounter while using WordPress. It’s create anxiety or nervousness for anyone that site is working fine just  before some hours and now it’s showing database connection  error whereas no changes was done in between.By keyed in Url of website ,Instead of showing home page it’s showing simple blank screen with message “Error establishing a database connection”  as follows


As a result of this incoming traffic , site’s ranking and reputation  impacted .Consequently it creates negative image of the website.

So first of all think positively and be cool and try to find out the key point behind the running concept of WordPress Website.

How does it work

How to Fix the Error Establishing A Database Connection in WordPress


1) Approach is based on programming language i.e. PHP Language and MySQL Database.

2)WordPress uses MySQL database to keep all posts, pages, files, theme, plugin, layout etc.

3) At any time website URL is keyed into the web browser, WordPress uses PHP instructions to extract all the respective deposited facts from MySQL database and flash on the screen.

If for some reason or another it was not able to connect to database and obtain the information from MySQL database through PHP commands than it reveal or view “Establishes database connection error” on a blank page as no particulars or details to shows up.

Probably base or root causes of “Error Establishing a Database Connection” in WordPress are following

1) Database being overcrowded if  too many parallels connections arise from shared hosts on the same servers.

2) Web Server that host’s database may be down for the time being.

3) From time to time database may be corrupt due to improperly way of written  plugin, theme, files etc., installation and deletion.

4) This can be because of a missing or singly corrupted table, or perhaps some figures were deleted by unfortunately.

5) Login data (username and password) may have been modified.  As a result  username/password of the WordPress database specified in the domain’s wp-config.php file do not match the actual username/password stored in MySQL.Although didn’t alter, it could have turned up by any means and WordPress site uses distinct login particulars to link to its MySQL database.

Complete Backup

Prior to any crack to tag the “error establishing a database connection” in WordPress and make any corrections in database always take a complete backup

There are as listed below choices to make a backup:

1)Download all web files from FTP. To do this, log into hosting account.

2)Export MySQL database through the Export function.

3)Set up a simple backup plugin like Updraft Plus, it works as follows to back up the data.

How to Fix the Error Establishing A Database Connection in WordPress
How to Fix the Error Establishing A Database Connection in WordPress

How To Fix “Error Establishing a Database Connection”


Steps 1 : Contact Web Host Provider  for Issues Related to Database Server

Asked if the database server is functioning with no problems. Host provider will confirm the database server running status that whether any hurdle or everything is fine.

Steps 2 : Checking the wp-config File for Connection Details

To open this file goes to:

Either Cpanel-> File Manager -> public_html-> wp-config.php 


FTP-> Filezilla  —–> public_html-> wp-config.php 

Right-click the wp-config.php files and selects a code editor such as perfect to open the file.

How to Fix the Error Establishing A Database Connection in WordPress

Once opened the wp-config.php file, check four important variables mentioned, which is mandatory to get connected to the database.

Details of database connection in wp-config.php

These are database name, database username, database password, and database host that is “local host” .In some cases there may be an IP address in place of “local host”.

/** The name of the database for WordPress */

define( ‘DB_NAME’, ‘Database Name’ );

/** MySQL database username */

define( ‘DB_USER’, ‘Database Username’ );

/** MySQL database password */

define( ‘DB_PASSWORD’, ‘Database Password’ );

/** MySQL hostname */

define( ‘DB_HOST’, ‘Host Name’ );

WordPress uses a unique username and password to connect to the database. Usually, those access details could not alter selfs.Although in some cases, very rarely, the access elements do modify. And with incorrect figures database access is denied, hence it generates – “error establishing a database connection”.

The amendment is done in the “wp-config.php” file where all the linkage details store which WordPress required to fetch the database. If any of these are not match, no connection will be fixed to server.

Confirm four lines particulars about connection from the “wp-config.php” file, with web host provider and if anything changed than correct it in “wp-config.php” file.

One thing always keep in mind that MySQL username ,password, database name should be always same with wp-config.php file and if any of them get change then it shown as database connection error.Therefore either change user details in database with same as wp-config.php or change wp-config.php to make it same with database config.

wp-config.php is the most essential file of WordPress. It contains all the database information. If changed root password, or the database user password, then need to change this file as well. First thing always check i.e. everything written in wp-config.php file should be same with database connection of MYSQL database.

Finally, re-upload the file via FTP.

Steps 3 : Check if the Same Problem Occur for /wp-admin/ Also ?

Check  WordPress dashboard – >

if the same error on both the front-end of the site, and the back-end of the site (wp-admin) i.e. “Error establishing a database connection”, then proceed onto the next step.If getting a different error on the wp-admin   i.e. “One or more database tables are unavailable. The database may need to be repaired”, then need to repair the database.

Steps for Repair the Database

Connect to site via FTP once again. Go to WordPress root and download the “wp-config.php” file to desktop.

Edit this file in notepad, add one extra line at the end (right before “That’s all, stop editing”):

define(‘WP_ALLOW_REPAIR’, true);

Now upload the file back to site (via FTP) .

Once done check the settings by visiting:

How to Fix the Error Establishing A Database Connection in WordPress

After repairing and optimizing the database, make sure to remove added line from wp-config.php.

Other option is to login on cpanel  ->MySQL@Databases

How to Fix the Error Establishing A Database Connection in WordPress

Click on Repair Database . It will repair the database. Then check whether the problem is resolved.

Steps 4 : Affix Corrupted Files Or Restore The Default WordPress Files

If by hook or cook overall correction of the database doesn’t work, the only aftermost option is to kickback any degraded files in WordPress. Many users, who fall short to tag the prime crunch, completely remove all of their files and the error vanishes.

As we are dealing with the main system files, need to be very cautious. The small fault can wash away whole site. Thus backup is always recommended.

Download a fresh copy of the WordPress CMS from

  1. Unzip it in drive and delete the whole wp-contents folder and the wp-config
  2. After wipe out the affected files, paste the rest of the files into WordPress root folder using the File Manageror an FTP client.

Hence forth after put back the damaged files with new one, reload the page.

Give your opinion in the below comment box. If you want, you can also post your articles on my website through post my blog menu.

2 thoughts on “How to Fix the Error Establishing A Database Connection in WordPress

Leave a Reply

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

error: Content is protected !!