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.
Linux Hosting with cPanel
Windows Hosting with Plesk
- Sign in to phpMyAdmin.
- In phpMyAdmin, in the left menu, select the name of the database your site uses.
- 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_).
- Connect to your hosting account with a file manager.
- Find and open the folder your WordPress site is in.
- 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';
- Check if the information in this file matches the corresponding current database details you obtained earlier.
- 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.
- yourtableprefix with the correct table prefix.
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.
- Save the updated wp-config.php file.
- Verify your site is back online by visiting your site with private browsing mode in Chrome, Firefox, or Edge.