Follow

How do I fix an Error Establishing Database Connection?

  • Applies to: WordPress Hosting
    • Difficulty: Medium
    • Time Needed: 15 minutes
    • Tools Required: SSH Access
  • Applies to: Grid Hosting
    • Difficulty: Medium
    • Time Needed: 15 minutes
    • Tools Required: Account Center

Overview

This article describes the process for resolving an "Error Establishing Database Connection" error. This is a very common WordPress error that can usually be resolved in a few minutes. 

Instructions

This error is caused by the database's inability to access the information in the database. Use the following troubleshooting steps to resolve the most common causes of this issue. 

If you have recently made changes to your site resulting in an "Error Establishing Database Connection", you may want to consider restoring from one of your available backups. These are automatically created by your WordPress hosting service and are easy to use.

Common reasons for receiving an Error Establishing Database Connection:

  • Improperly configured wp-config.php file.
  • The database user does not have permission to access the database
  • A problem with the server itself

The most common cause of an Error Establishing Database Connection is an incorrectly configured wp-config.php file. Among other important items, the wp-config file contains the connection information for the WordPress site's associated database.

To verify that your wp-config file is set properly, open it using the Grid file manager (domains/yourdomain.com/html/wp-config.php) or connect to your server via ssh and use a BASH text editor.

Via the file manager:

1. Navigate to the Grid File Manager and locate the wp-config.php file. Open the file using the edit icon to the right. 

 

2. Identify the database connection information. If any of these items are incorrect, you will receive an Error Establishing Database Connection. 

wpconfig.png

  • Be sure to make a copy of this file before editing it. Simply select the text and copy it to a notepad or similar.

 

The wp-config.php file is automatically set during the Managed WordPress provisioning process. This includes many Media Temple specific settings that you may be unable to restore on your own. It is not recommended that you alter this file. If you've altered wp-config.php and your site has been negatively impacted, Media Temple can restore it for you. To verify that your wp-config file is set properly, open it by connecting to your server via ssh and use a BASH text editor. Identify the following section:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'mbbo3640112376');

/** MySQL database username */
define('DB_USER', 'wp_user124235');

/** MySQL database password */
define('DB_PASSWORD', 'b6zQc2BZ.L');

/** MySQL hostname */
define('DB_HOST', $_ENV{DATABASE_SERVER});

  Verify that the information is correct:

  • Database name: This is the name of the database that WordPress connects to. For 1-click installs, this is automatically configured and should be correct unless you have made changes. If you are unsure of what the proper database name is, do the following:
  1. Log in to phpMyAdmin. You will see a list of available databases on the left side that the database user has access to. 
  2. Select a WordPress database and then identify the _wpoptions table.
  3. Click on the _wpoptions table to list its contents using the Browse tab. This table should include the site URL and home. If this value matches the address of your WordPress site, this is likely the proper database.  
  • Database Username: The database username may be set properly in wp-config.php, but the assigned user does not have permission access to the database. Make sure that the database username is set to a user that has permission to access to the database. This is more likely to be an issue if you have recently migrated a WordPress site from a different location and did not create the database user or give the user proper permissions.
  • Database Password: If you are unsure of the database password, reset the database user's password using the database user management tool in the account center, and then use that new value for the database password field.
  • Database Hostname: The database hostname is the address of the database server. Unless you are connecting to an external database, the database hostname should be set to 'internal-db.s00000.gridserver.com'. Replace this information with the information found in your server guideIf you have installed WordPress via the 1-click installation tool, you may see "('DB_HOST', $_ENV{DATABASE_SERVER});". This will work fine and can be left in place.

 

  • Database name: This is the name of the database that WordPress connects to. If you have made changes to the original configuration and are unsure of what the proper database name is, log in to phpMyAdmin. Your WordPress hosting database will be listed on the left.
  • Database Username: The database username is the user that has access to the database. If you are unsure of this, you must either restore the wp-config.php file from an available backup, or contact Media Temple so that we may assist you. 
  • Database Password:The database password is the password for the user that connects to the database. If you are unsure of this, you must either restore the wp-config.php file from an available backup, or contact Media Temple so that we may assist you. 
  • Database Hostname: The database hostname is the address of the database server. Unless you are connecting to an external database, the database hostname should be set to "('DB_HOST', $_ENV{DATABASE_SERVER});". This is analogous to the "local host" setting of many servers. If you have changed the hostname and do not know what the value is supposed to be and also do not have an available backup to restore from, please contact Media Temple's 24/7 support team so that we can restore your default wp-config.php file. 

 

If you have followed the above steps but are still receiving an Error Establishing Database Connection screen, the problem may be with the database server itself. For help with this, please contact Media Temple's award-winning 24/7 support so that we may further assist you. 

Resources

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk