Error-Establishing-a-Database Connection in WordPress

How to Fix – Error Establishing a Database Connection in WordPress

What You'll Learn

Error Establishing a Database Connection in WordPress

You try to load your WordPress site and there it is, this blank white screen that simply says “Error Establishing a Database Connection”.  It’s such a simple page but infuriating. What does it mean and why does it keep your site from doing anything?  Knowing how to fix the error establishing a database connection in WordPress is usually a quick fix but does require a bit of technical know-how.

WordPress uses the database to store a bunch of information including user information, post content, settings, and a lot more. When WordPress can’t connect to the database, you only have half of what you need to run the site and it just won’t work. 

The error establishing a database connection in WordPress means that WordPress can’t connect to the database and is usually caused by one of a handful of problems

  • A problem accessing the database because of user settings or other settings
  • A problem with the database itself
  • A problem with the server (computer) where the database lives

How to Fix the Error Establishing a Database Connection in WordPress

To get started, you will need file access to your server.  If you’re using the Control Panel that is on most major hosts like A2 Hosting and Siteground, then that’s pretty easy.

Accessing the Files on Your WordPress Host

First, log into the control panel on your hosting.  You should see an option for the File Manager.  Open that.

C-Panel File Manager
File Manager Siteground

Each server is a bit different, but you’ll need to get to the directory where your WordPress installation is installed.  Usually, this is in a directory called something like public_html.

WordPress public_html address

Fixing the Database Connection in the Configuration Settings

WordPress needs certain information to connect to the database.  It needs

  • Database server
  • Database name
  • Database username
  • Database password
RELATED:   Fix Fatal Error: Maximum Execution Time Exceeded in WordPress

For our examples, we’re going to use the following

  • Database server – localhost
  • Database name – WPDBName
  • Database username – dbuser
  • Databasepassword – dbpassword

Make sure to change any values in our examples with the real values from your hosting. 

To find those values, you need to look in your Control Panel.  There is usually a section called something like databases.

The most common cause of the error establishing a connection to the database is when WordPress has the wrong information to connect to the database. We are going to check that first.

  • Looking for the wp-config.php file in the File Manager.  Right click on it and select edit.
wp-config in File Manager
  • Open that file
  • Scroll down until you find a section that looks like this:
wp-config database settings
  • Now we will need to check the settings. We need to make sure that what we have in the configuration file is the same as what the server has.
Error Establishing a Database Connection in WordPress
Error Establishing a Database Connection in WordPress
Fixing Error Establishing a Database Connection in WordPress

Checking Database User Information on C-Panel

The next part has a few steps, so let’s summarize and then give you the details:

Go to the section labeled “Databases” select MySQL Databases.

C-Panel MySQL Databases
Getting to Database Settings on C-Panel

Scroll down to the Current Databases section and look for the database that was listed in your wp-config file. If it doesn’t then you will need a developer or your host to help figure out what happened to your data. To the right, you will see the user (or users) that have access to the database. Make sure the user from your wp-config file is listed.

Control Panel Current Database
Question Mark

Does your user have access to the database? Then we need to make sure the user exists and their password is right.

If not, then we need to create the user.

Looking at Current Database Users in C-Panel

If that’s all good, then keep scrolling down. At the bottom is the Current User section. Look there to see if the user is there. If they are, then try selecting “Change Password” and set the password to what’s in the wp-config file.

Control Panel Current Users
Control Panel – Current Users

Adding a New Database User in C-Panel

If the user doesn’t exist, we need to make them and then give them access to the database. Scroll up to the Add User section. Fill out the username and password with what is in your wp-config file.

Control Panel - Add User
Control Panel – Add User Screen

Checking Database User Information on Siteground

Troubleshooting Error Establishing a Database Connection in WordPress is very similar in Siteground but there are a few differences. Let’s take a look at some of those difference.

RELATED:   Fix Fatal Error: Maximum Execution Time Exceeded in WordPress

On the left bar in the Site Tools, click Site. That will open a new window. Select MySQL.

Siteground MySQL

On the next screen that opens, you will see the databases at the bottom. What’s nice about the Siteground interface is they more clearly indicate which database goes with which website. Check that the database for your website is there and that it matches the value in your wp-config file. If they don’t, you’ll need to get some assistance from Siteground or a developer to figure out what happened to your data.

Siteground’s support is really good and it’s worth starting there. You may need to restore from a backup.

Checking Database Users on Siteground

Near the top of that page, you’ll see a navigation bar. Select USERS.

Siteground Database Bar

This will open a new page with user information. Scroll to the bottom and see if the user from your wp-config is listed.

Siteground Database Users

If your user is listed, select the three dots under action and select Change Password. Then change the password to what is listed in your wp-config file..

Siteground Database Users Menu Expanded

If your user isn’t listed select CREATE USER. This is a bit different. Siteground creates the user name and password, so you will need to copy those down.

Siteground New Database User

Press Manage Access. A new form will open up. Usually, you can just press confirm. Select your database in the dropdown and press All Privileges. Go back to your wp-config file and change the DB_USER value to your new user and the DB_PASSWORD value to the new password.

Siteground Add Database to User

Does Your Site Work Now?

Try your site again. This will usually fix the issues. If it does, you’re all set. If not, we have a bigger problem. You may need some help from here.

Leave a Comment

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap