How to Fix the Error Establishing a Database Connection in WordPress?

Error Establishing a Database Connection in WordPress.

  1. Bhawani Singh
    The biggest fear of every WordPress user is to get an error message “Error Establishing a Database Connection”. This error can occur when you type anything in URL bar and want to search anything. There can be many reasons by which this error can occur. If you are a WordPress website owner and you have this error on your website, it can be very harmful for your website. You can lose your web traffic and no one would like that. To lose the traffic can cause to lose the customers of website and it will be bad for business.

    The WordPress uses PHP and MYSQL for its websites. When the system shows the “Error Establishing a Database Connection” error it means that PHP code is unable to make connection with MYSQL database. It can happen due to various reasons.

    Reasons of this error:

    When the system shows the error of not connecting to database, there can be many reasons behind this problem. Some of the important reasons are given below:

    • When the login credentials for database are wrong: The database of the website needs the different log in ID and password to be accessed. If the wrong ID and password are entered in system to log in to database, it will not connect to system. If you have recently changed the user name and password of database and you are trying to log in by using old credentials then it can cause to lose connection to the database.

    • Any type of corruption in database: The system can lose the connection with server if the database is corrupted or have any damage. The database can have damage due to the various reasons. If the system has installed any bad or harmful plug in then it can cause corruption to the database. It can also be corrupted because of any lightning strikes to server.

    • The hosting server of database is down: The database of the system works with the help of hosting services. If there is any problem in hosting server and it gets down, it can cause this error in system. You have to consult your web hosting service providers to get rid of this problem. The server which hosts the database can be down due to various problems.

    These are the main reasons which can cause the “unable to establish connection to database” error in system.

    Troubleshooting options to fix this error:

    If you are also getting the same error in your wordpress, you can fix this error by using the following tips for troubleshooting:

    Determine the location of error:

    To get rid of this error, you have to determine the location where this error is occurring. May be the error is occurring on some specific points or it can be on specific page of website. Then you can use the troubleshooting tool to fix the error. The Wordpress has built in feature for troubleshooting and repair database. For that you have to access your wp-config.php file and add this line in the bottom :

    This line will enable you to optimize and repair your database by navigating to (just replace “” with your actual URL).

    Check the database login settings in wp-config:

    The database can lose the connection due to any fault in log in information. If you are missing any credential or using any wrong character in user ID or password then it can cause error. You should confirm the log in details of database. You should go to the wp-config for it. There you will check the log in details and will fix the error which you find there.

    1. Name of the database (“DB_NAME”)
    2. Database username (“DB_USER”)
    3. Databse User password (“DB_PASSWORD”)
    4. Database host (“DB_HOST”)
    If any one of these values is incorrect, WordPress will not be able to connect to the database.

    Consult the Web hosting company:

    Hope that you will be able to fix the error by using these techniques. If you are still getting the error, it can be caused because of hosting server is down. You should consult the web hosting company to fix this error. You can also wait till the hosting server starts working.

    So you can fix the error of “unable to establish connection with data base in WordPress” by using these techniques. These troubleshooting options will work according to the reason of error so you must have to know about the reason to fix the error.