How to update WordPress database configuration settings

This article describes how to update database configuration settings in WordPress. You may need to do this if WordPress cannot connect to the database.

PROBLEM

When you try to view a WordPress site, you may receive the following error message:

Error establishing a database connection

This error occurs when WordPress is unable to connect to the specified database in its configuration settings. This usually occurs because the WordPress database configuration settings in the wp-config.php file are incorrect. For example, an account migration or WordPress database import can cause the database specified in the wp-config.php file and the actual database to differ.


RESOLUTION

To resolve this problem, first determine the correct MySQL database settings. Then you can update the wp-config.php file with the correct database settings. To do this, follow the procedures below.

Step 1: Determine the correct MySQL database settings

To determine the correct MySQL database settings, follow these steps:

  1. Log in to cPanel.
  2. In the Databases section of the cPanel home screen, click phpMyAdmin.
  3. In the left-hand pane of phpMyAdmin, note the name of the WordPress database that you want to use.


    Note: Typically, the WordPress database is username_wpXXX, where usernamerepresents your cPanel username, and XXX is a three-digit number. However, if your account was recently migrated (for example, from another hosting provider), the database name may be in a different format.



  4. Click the name of the WordPress database that you want to use. A list of tables in the database appears.
  5. In the Table column, note the table prefix that is used in the table names.


    Note: Typically, the WordPress database table prefix is wp_. However, if your account was recently migrated (for example, from another hosting provider), the table prefix may be different, or even nonexistent.



  6. In the Databases section of the cPanel home screen, click MySQL® Databases.
  7. Under Current Databases, locate the database that you noted in step 3.
  8. Note the database username for the database.

    • If you do not know the password for this database user, you should reset it now.

 

Step 2: Update the wp-config.php file

After you have determined the correct database settings, you are ready to update the wp-config.php file. To do this, follow these steps:

  1. In the Files section of the cPanel home screen, click File Manager.
  2. Navigate to the directory where WordPress is installed.


    Note: Typically, WordPress is installed in the public_html (document root) directory. However, if you installed WordPress in a subdirectory, navigate to that directory instead.



  3. Right-click the wp-config.php file, and then click Edit.
  4. Locate the DB_NAME setting, and then replace the value with the name of the WordPress database that you obtained in the previous procedure. For example, if your database name is username_wp123, modify the text as follows:

            define('DB_NAME', 'username_wp123');

 

  1. Locate the DB_USER setting, and then replace the value with the database username that you obtained in the previous procedure. For example, if your database username is username_wpuser, you would modify the text as follows:

            define('DB_USER', 'username_wpuser');

 

  1. Locate the DB_PASSWORD setting, and then replace the value with the database user's password. For example, if your database user's password is example_password, modify the text as follows:

    define('DB_PASSWORD', 'example_password');


    Note: It should go without saying that you should not use example_password as a password on a real installation!



  2. Confirm that the DB_HOST setting is set to localhost as follows:

            define('DB_HOST', 'localhost');

  1. Locate the $table_prefix setting, and then replace the value with the database table prefix that you obtained in the previous procedure. For example, if the database table prefix is wp_, modify the text as follows:

            $table_prefix  = 'wp_';

            If your database does not use a table prefix, modify the text as follows:

            $table_prefix  = '';

  1. Click Save Changes.
  2. Use your web browser to go to the WordPress site's URL. The site should now load.

 

  • WordPress
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Add MailChimp Subscribers from WordPress

You can add subscribers directly to a MailChimp mailing list from WordPress. This article...

Broken Image Links in WordPress

This articles describes how to resolve a problem that may occur when you try to add images to a...

How to Add CAPTCHA Protection to a WordPress Site

This article describes how to add CAPTCHA protection to a WordPress site using the Google CAPTCHA...

How to Add External RSS Feeds to your WordPress Site

This article demonstrates how to add an external RSS feed to a WordPress site. RSS (Rich Site...

How to Add a Custom Logo to WordPress

This article describes how to add a custom logo to a WordPress site. Adding a logo to your...

Powered by WHMCompleteSolution