How to fix the “Error Establishing a Database Connection” in WordPress

On this page
  1. Locating your Database Credentials
  2. How to Reset and Sync the Password
  3. Distinction Block
  4. Practical Implications
  5. Summary

When your WordPress site displays this error, it means the PHP code is unable to link up with the MySQL database where your posts, pages, and settings are stored. On the mybox infrastructure, this is almost always due to a mismatch in the login credentials stored in your configuration file.

This typically happens after a database password has been reset in the dashboard or if the wp-config.php file was edited incorrectly.

Locating your Database Credentials

To fix the connection, you must compare the data in your website’s configuration file with the actual settings in your mybox panel.

  1. Connect to your server via FTP or SFTP.
  2. Navigate to your website’s root directory (usually public_html).
  3. Open the wp-config.php file and look for these three lines:

PHP

define('DB_NAME', 'database_name');     // The name of the database
define('DB_USER', 'database_user');     // Your MySQL username
define('DB_PASSWORD', 'your_password'); // Your MySQL password

How to Reset and Sync the Password

If you are unsure what the correct password is, the most reliable fix is to set a new one in the mybox panel and then update the file.

1. Set a new password in the panel

  • Log in to your mybox dashboard and go to Databases > MySQL Users.
  • Find the user listed in your wp-config.php file (the DB_USER value).
  • Click Change password.
  • Enter a new password or use the generator, then save the changes.

2. Update the configuration file

  • Go back to your wp-config.php file in your text editor.
  • Replace the old value in DB_PASSWORD with the exact password you just created in the panel.
  • Save the file and upload it back to the server.

Distinction Block

Database User vs. Panel User Your mybox panel login is different from your MySQL User login. WordPress needs the specific MySQL credentials found in the “Databases” section to access your site data.

Practical Implications

  • White Screen vs. Error Message: If you see a completely blank screen instead of the database error message, you may also need to enable WP_DEBUG to see if there are additional PHP errors.
  • Database Host: In the wp-config.php file, there is also a DB_HOST line. On the mybox infrastructure, this is usually set to localhost. Do not change this unless specifically instructed by support.
  • Table Prefix: If you have recently migrated your site and the connection is successful but the site looks “empty,” check the $table_prefix line in wp-config.php. It must match the prefix used by the tables in your database (e.g., wp_).

Summary

The “Error Establishing a Database Connection” is a simple “wrong key” problem. By verifying the database name, username, and password in your mybox panel and ensuring they match your wp-config.php file exactly, you can restore your website to full functionality.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.