Fix Error establishing a database connection in WordPress
WordPress uses connection strings to know which database to connect to. When your site is not connected to your database, it displays the Error establishing a database connection notification. To resolve this error, update the connection strings on your WordPress site.
- An FTP app to open and edit your site files. There are many third-party FTP apps available, we recommend the FileZilla FTP app.
- A text editor to make the necessary changes in WordPress files. There are many third-party text editors available, we recommend Notepad++. Do not edit files with a word processing application like Microsoft Word.
- The database name, username, password, and host name for your WordPress site. Find these details for your Linux Hosting with cPanel, Windows Hosting with Plesk, or Managed WordPress plan. If you’re using cPanel or Plesk, you’ll need to reset and use a new password.
- If you moved your site to a new server, make sure that you obtain the credentials for the new database which you plan to use, as described above. You can't use credentials for the old database on the new server.
- Sign in to phpMyAdmin.
- In phpMyAdmin, on 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 FTP. Find and open the folder your WordPress site is in.
- In the wp-config.php file, locate the section that looks like 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 database details you found earlier.
- yourdatabasename: Replace this with your MySQL database name.
- yourusername: Replace this with your MySQL username.
- yourpassword: Replace this with your MySQL password.
- yourhostname: Replace this with your MySQL hostname.
- yourtableprefix: Replace this with your table prefix.
Note: If any of the information in the wp-config.php file doesn't match your database details, then update the file with the correct information.
- Save the updated file.
- Verify your site is back online by visiting your site with private browsing mode in Chrome, Firefox, or Edge.