Close Menu
    Facebook X (Twitter) Instagram
    Oixiesoft
    • Home
    • Services
      • WordPress Malware Removal
      • Fix WordPress Errors
      • WordPress Website Development
    • Articles
    • Contact
    Oixiesoft
    Home»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 StaffUpdated:September 27, 2025No Comments4 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. 

    What Is The “Error Establishing a Database Connection”?

    The “Error Establishing a Database Connection” is a common issue encountered in web development when a website is unable to establish a connection with its database. T

    his error typically arises from misconfigurations in the website’s database settings, such as incorrect database credentials, server unavailability, or database corruption. When a user tries to access the website, and the connection to the database fails, this error message is displayed.

    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

    The second method to repair wordpress database to check MYSQL Server status

    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

    WordPress Pharma Hack – How To Fix

    How to Set Post Expiration Date in WordPress

    How to Enqueue Scripts Using wp_enqueue_scripts Hook in WordPress

    WordPress Pharma Hack – How To Fix

    How to Set Post Expiration Date in WordPress

    How to Enqueue Scripts Using wp_enqueue_scripts Hook in WordPress

    How to Update PHP in WordPress Safely

    How to Fix Broken Permalinks in WordPress?

    Fixed Unable to Create Directory wp-content/uploads. Is its Parent Directory Writable by the Server.

    WordPress Memory Limit – How to Fix or Increase the PHP Memory Limit

    How To Fix Japanese Keyword Hack In WordPress Site?

    How to Add Bullet Points & Numbered Lists in WordPress

    How to Properly Use Heading Tags in WordPress

    How To Fix the “Missing a Temporary Folder” Error 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 2024

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

    How to remove Malware from WordPress website?

    Services
    • Web Development
    • Mobile Application Development
    • WordPress Malware Removal Service
    • Website Design
    • WordPress Development
    • Magento Development
    • Shopify Development
    • SEO Services
    Blog
    • How to Fix the Error Establishing a Database Connection
    • Ping List WordPress
    • How To Fix Japanese Keyword Hack
    • How to remove Malware from WordPress
    Hire Developers
    • Hire WordPress Developer
    • Hire Shopify Developer
    Contact Info
    • Oixiesoft Technologies
      A-40, Block A, I thum Tower, Sector 62, Noida
    • [email protected]
    • Privacy Policy
    • About Us
    • Contact Us
    © 2025 OixieSoft Technologies

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