How to fix the “Error establishing a database connection” in WordPress on Spaceship Hosting

The “Error establishing a database connection” message in WordPress means that the website cannot connect to its database. In most cases, this happens due to incorrect database access details in the WordPress configuration file:



In this guide, we’ll cover the most common causes of this error and guide you through the steps to fix it.


What can cause this error?

In most cases, the "Error establishing a database connection" error occurs when WordPress is using incorrect database access details. This often happens after:

  • Migrating a website to a new hosting provider

  • Changing database passwords

  • Restoring a backup

  • Manually editing configuration files

  • Moving files between servers or hosting plans


Check database connection details

WordPress connects to its database using a database name, a database username, a password, a database host, and the access privileges assigned to the database user.

Thus, it’s needed to make sure all of the following conditions are met:

  • The database name exists on the server and matches the existing database name

  • The database username matches the existing database user

  • The password is correct for that user

  • The database user is assigned to the database

  • The user has full access privileges (ALL PRIVILEGES)


How to verify database details?

All database connection details are stored in the wp-config.php file, located in the root directory of your WordPress installation. To check and verify them, do the following:

  1. Log in to your cPanel and go to File Manager:


  2. Navigate to your WordPress root directory and open the wp-config.php file (via Edit or View options):




    Note: When choosing Edit, you may want to create a backup of your wp-config.php file:


  3. Look for these lines that contain the database name, user, and password:


  4. In another tab, open the Manage My Databases menu:




  5. Attentively check if the database name and user match the ones specified in wp-config.php:


  6. Scroll down and ensure that the database user indeed exists on the server:



  7. There is no possibility to see what password is set for a database user, so it is necessary to set it by clicking Change Password:



  8. Update the values in wp-config.php if needed.

  9. Ensure the correct database user is assigned to the database and has All Privileges enabled (click on the user >> checkmark All Privileges >> Make Changes):




  10. Refresh your website! If the credentials are correct, the website should load normally.


Still seeing this error?

If the database credentials are correct and the error is still present, the issue may be caused by:

  • A corrupted database

  • A temporary MySQL server outage

  • Damaged WordPress core files 

At this stage, please contact our Support Team so that we can check the database service status and logs.

A valid email is required