Facebook Twitter Instagram
    Facebook Twitter Instagram
    Oixiesoft Oixiesoft
    • Home
    • html
    • PHP
    • Python
    • Node.js
    • WordPress
    • Ask with Expert
    Oixiesoft Oixiesoft
    Articles»Wordpress»How to Fix the Error Establishing a Database Connection in WordPress
    Wordpress

    How to Fix the Error Establishing a Database Connection in WordPress

    Editorial StaffBy Editorial StaffNo Comments3 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    “Error establishing a database connection” is the most common error you face in WordPress. This error means your site is unable to connect to the database. Sometimes this error occurs during the updating, installing or migration the WordPress. Sometimes, It will happen due to the other reasons like SQL server is down, hosting issue etc. 

    how to fix error establishing database connection

    You can  identify all possible reasons and appropriate solutions by following methods:

    How to Fix the Error Establishing a Database Connection in WordPress

    These are the main reasons of an error establishing a database connection:

    • Wrong MYSQL database login details in wp-config file
    • Database server is unresponsive or down
    • WordPress database is corrupted
    • MYSQL Database User Has Limited Privileges

    1. Wrong Mysql Login details:

    Wrong credentials are the most common cause of the error establishing a database connection. You can fix it easily.

    You have to check wp-config.php file that contains all details of the database. Open your wp-config.php file via cpanel filemanager or your favorite FTP client. Check the following details:

    define('DB_NAME', 'database-name');
    define('DB_USER', 'database-username');
    define('DB_PASSWORD', 'database-password');
    define('DB_HOST', 'localhost');

    If you change your hosting and migrate the site to another server, you should change the above details with new server details. Some cloud hosting uses a separate DB host instead of localhost, so you should change it very carefully with the new credentials.

    Many times this error is fixed by changing the hostname to the IP address as follows:

    define('DB_HOST', '176.0.0.5:22');

    2. MYSQL Server is down

    If your site is a very heavy traffic site, you can get this error during peak hours for some users. It happens due to high database queries.

    In this situation, it will be fixed after restarting the MySQL service. So, Contact your hosting provider to know whether your Mysql server is down or not. If it is down your host will fix it. If you have a cloud or VPS server, you can fix it by restarting the MySQL service.

    You can test the server status by creating testconnection.php in your installation root directory. After creating this file add the following code:

    <?php
    $link = mysql_connect('localhost', 'mysql_user', 'password');
    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }
    echo 'Congratulation Connected successfully';
    mysql_close($link); ?>

    In line no.2, change mysql_user and password value with username and password.

    Now open this file in the browser by typing yoursite.com/testconnection.php

    If you can see the page ”Congratulation Connected successfully”, All service is up and running. If not connected and get the access denied error, contact your hosting provider.

    3. WordPress database is corrupted

    Many times, It may happen due to a corrupted database and the need to repair the database. You can repair a corrupt WordPress database by following the below steps:

    Add the following line to the wp-config.php file

    define('WP_ALLOW_REPAIR', true);

    Now open the following URL in browser:
    http://www.yoursite.com/wp-admin/maint/repair.php

    fix corrupt adatabase

    Click on the button “Repair” or “Repair and Optimize”. WordPress will repair your database in a few minutes. Do not forget to delete the above function from the wp-config.php file after repairing the database.

    4. MYSQL Database User Has Limited Privileges

    If none of the above methods works, then apply this method.

    1. Delete the current MySQL user that is connected to the database.
    2. After deleting the current user, Create the new user and give the full privileges to the newly created User.
    3. Now open the wp-config.php file and replace the old database username with the new username and save it.

     

    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Tumblr Email
    Editorial Staff

    Related Posts

    How to Create a Sitemap in WordPress

    How to Disable Emojis in WordPress

    How To Turn Off The RSS Feed In WordPress

    How to Create a Sitemap in WordPress

    How to Disable Emojis in WordPress

    How To Turn Off The RSS Feed In WordPress

    How to Enable Customer Tracking in WooCommerce with Google Analytics

    How to Easily Add Icon Fonts in Your WordPress Theme

    How to Display Your Facebook Page Reviews in WordPress

    How to Start a Podcast (and Make it Successful) in 2023

    How To Fix “The Link You Followed Has Expired” WordPress Error

    How to remove Malware from WordPress website?

    How to get Paypal Client ID and Secret Key?

    How to clean up WP head-tag and improve page speed (2023 guide)

    How To Fix the “cURL Error 28: Connection Timed Out”

    7 Best WordPress Contact Form Plugins of 2023

    How to Fix There Has Been a Critical Error on Your Website in WordPress

    4 Must Have WordPress Plugins for Business Websites in 2023

    How to filter by featured products in admin in Woocommerce

    How to Fix the Error Establishing a Database Connection in WordPress

    How to Add an Admin User in WordPress using FTP

    Updated WordPress Ping List 2023 – Faster Indexing Of New Post

    How to Change Permalinks in WordPress

    • Privacy Policy
    • About Us
    • Contact Us
    © 2023 OixieSoft Technologies

    Type above and press Enter to search. Press Esc to cancel.