GoDaddy Help

Fix Error establishing a database connection in WordPress

Note: This article describes the troubleshooting process for the Error establishing a database connection. If you are unsure which error is causing issues on your site, check out the article about the most common WordPress errors with suggested solutions.

To work correctly, your WordPress site must be connected to a database. WordPress uses connection strings stored in the wp-config.php file to try and make a database connection. If the connection cannot be established, you’ll see the Error establishing a database connection notification on your site. The most common method to fix this error is to update the connection strings in the wp-config.php file.

Note: Resolving the Error establishing a database connection requires advanced troubleshooting methods, which include connecting to your server, obtaining database credentials and prefix and editing the wp-config.php file. If you’d like a GoDaddy expert to fix this for you, our WordPress Premium Support team can help.

Required: You'll need the correct database details to complete all steps in this article. Database details are different from your WordPress login credentials and here's how to find them for different hosting plans:
Managed WordPress

Follow the steps from this article, and copy the details to a text editor of your choice. The database name is same as the database username and you should also copy the port number.

Linux Hosting with cPanel

Follow the steps from this article to obtain the database name and username in cPanel. Since password is not visible for security reasons, here's how to reset the database password. For host name, you should always use localhost.

Windows Hosting with Plesk

Follow the steps from this article to obtain the database name, username and host name in Plesk. Since password is not visible for security reasons, here's how to reset the database password.

  1. Sign in to phpMyAdmin.
  2. In phpMyAdmin, in the left menu, select the name of the database your site uses.
  3. Make note of the database prefix. The database prefix is appended to the table names (for example, if you see the following database tables: wp_3f_options, wp_3f_ posts, wp_3f_postmeta, etc., your database prefix is wp_3f_).
  4. Connect to your hosting account with a file manager.
  5. Find and open the folder your WordPress site is in.
  6. In the wp-config.php file, find the section that looks similar to this example:
    /** The name of the database for WordPress */
    define('DB_NAME', 'yourdatabasename');
    /** MySQL database username */
    define('DB_USER', 'yourusername');
    /** MySQL database password */
    define('DB_PASSWORD', 'yourpassword');
    /** MySQL hostname */
    define('DB_HOST', 'yourhostname');
    
    $table_prefix  = 'yourtableprefix';
  7. Check if the information in this file matches the corresponding current database details you obtained earlier.
  8. If any of the information in the wp-config.php file does not match your database details, update the file with the correct information. Be careful to replace only the strings within the apostrophes since changing anything else may cause additional issues with your site. In the example above, you should replace:
    • yourdatabasename with the correct MySQL database name.
    • yourusername with the correct MySQL username.
    • yourpassword with the correct MySQL password.
    • yourhostname with the correct MySQL host name.
    • Note: If your site is hosted on Managed WordPress, the row with the host name should have the following structure: define('DB_HOST', 'yourhostname:portnumber'); You should replace yourhostname with the correct MySQL host name and portnumber with the correct port number.

    • yourtableprefix with the correct table prefix.
  9. Save the updated wp-config.php file.
  10. Verify your site is back online by visiting your site with private browsing mode in Chrome, Firefox, or Edge.

More info