Update WordPress database connection strings
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.
Required: You'll need the following to complete all steps in this article:
- 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 (cPanel / Plesk / Managed WordPress) plan. If you’re using cPanel or Plesk, you’ll need to reset and use a new password.
Warning: You should always backup your site before performing any troubleshooting.
- 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 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 User Name.
- yourpassword: Replace this with your MySQL password.
- yourhostname: Replace this with your MySQL Host Name.
- 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.
- Visit your site in a browser with private browsing mode (Chrome / Firefox / Edge) to verify it's back online.
