Error Establishing a Database Connection in WordPress & Ways To Fix It.
Get Quote
×

    Indylogix Website - IndyLogix Solutions

    Let's Discuss Business Together

    +
    Address
    406-408, Devnandan Mega Mall, Opp. Sanyas Ashram, Ashram Rd, Ellisbridge, Ahmedabad, Gujarat 380006

    The ‘error establishing a database connection’ is the most common type of error seen in a WordPress website. It is a disastrous error that causes your WordPress website unavailable for the users. The user encounters this error when WordPress is not able to establish a connection with the database. There are a lot of things that can influence your WordPress database connection which makes it quite challenging for the beginner level developers to diagnose the problem and find out the solution.

    If you are also facing such kind of issue with your website, hire WordPress developers now to fix it as soon as possible as this is something that should be taken seriously and fixed quickly negligence of which may lead to harmful consequences for your sales as well as traffic. 

    Meanwhile, let us discuss more about the issue and understand the same in detail. We will also discuss a few general situations that make up this error as well as simple ways to get your site back on track in the least possible time.

    WordPress Database Error – The Introduction and Causes

    Entire information present on your WordPress site like post data, page data, meta information, plugin settings, login data, etc. is saved in the MySQL database except the media content including images and the theme/plugin/core files like index.php, wp-login.php, etc. Whenever a user visits your website, PHP runs the code on the page and asks the information from the database and the information is then displayed to the visitor with the help of the browser. However, if the system is not able to establish the connection for any reason, the user is left with the ‘ error establishing a database connection’ message, as shown in the subsequent image.

    You can see that the whole page is empty as no data can be obtained to execute the page due to a faulty connection. It not only crushes the frontend of your site but also blocks you from entering your WordPress dashboard.

    The main reasons behind the occurrence of ‘error establishing a database connection ’ include defective database, an unresponsive database server, or inaccurate database information in your WordPress settings. 

    Now, let us focus on how to fix the ‘error establishing database connection’ issue in WordPress.

    Checking the WordPress Database Credentials

    Inaccurate database credentials are one of the most obvious causes behind the occurrence of database connection error especially when you have lately transferred your site to a new host. The wp-config.php file is a WordPress configuration file that holds crucial WordPress settings involving database information. Your WordPress database credentials are also saved in this file. You are required to ensure that all the information stored in the file comprising the database name, username, password, and database host is accurate.

    Cross-check the following lines in the wp-config.php file.

    1

    2

    3

    4

    5

    6

    7

    8

    9

    // ** 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’, ‘username_here’ );

    /** MySQL database password */

    define( ‘DB_PASSWORD’, ‘password_here’ );

    /** MySQL hostname */

    define( ‘DB_HOST’, ‘localhost’ );

    Checking the Database Host

    Once you have confirmed that all the information comprising your database name, username, and password is accurate, you are required to put a check on your database host information to ensure that you are utilizing the right one. 

    Many WordPress hosting companies make use of the localhost as your database host. But, the maintained WordPress hosting companies may employ distinct servers to host databases. Your database host information is not expected to be localhost in such cases. 

    Hence, contact your WordPress hosting company and verify your database host information.

    Improving the WordPress Database

    Sometimes, you may see a different kind of error like  “One or more database tables are unavailable. The database may need to be repaired”. You are required to repair your database in such cases.

    This can be done by combining the subsequent line in your wp-config.php file. You are required to combine it ahead of ‘That’s all, stop editing! Happy blogging’ line in wp-config.php file. After finishing the repairing and optimization of the database, ensure to eliminate this code from your wp-config.php file.

    define(‘WP_ALLOW_REPAIR’, true);

    Checking if WordPress Database is Down

    If everything else looks fine and still the WordPress is not able to establish the connection with the database then perform a check on your database server as it may be down. This can happen as a result of massive traffic on the server. Usually, your hosting server is not able to manage massive load particularly in the case of shared hosting. Your site may get down in such cases and users can even encounter errors. Hence, get in touch with your hosting provider asap to make sure your MYSQL server is working properly. 

    Additional Tips

    In addition to the above-mentioned tips, you can also try for a few more tips in order to get the issue resolved. These tips include

    1. Updating the site URL

    Try to update the WordPress website’s URL by making use of phpMyAdmin.

    2. Rebooting the webserver

    The dedicated servers, local servers, and virtual private servers (VPS) users can

    attempt rebooting their servers that will restart their web as well as a database server. Hence, a few temporary issues generating the error may get fixed as a result.

    3. Asking for help

    If you are still not able to fix the issue then get in touch with your web hosting company. A reliable WordPress hosting company can help you to find out the issue, guide you in the appropriate direction, or even solve the issue for you.

    Hope this article will prove to be a great help for you to settle the ‘error establishing a database connection’ in your WordPress website.

    However, if you are still not sure how to fix the issue and need help, hire experienced WordPress professionals from our team to get the issue fix at affordable prices!