blog14

Establishing a database connection error

One of the most commons errors you might run into when creating a WordPress site is the well known ‘Error establishing a database connection’ error.

This error will show on your front page if WordPress is unable to connect to your database. A surprising amount of things can cause this error to show.

Today we’ll show the most common reason for this error, and how to fix it. To show you these we will be assuming you are using our hosting services. In case you aren’t yet but are interested in knowing more, check out our offerings here.

If you do use our hosting, check out our tutorial on installing WordPress in 1 minute, as following this should keep you from encountering this error.

What causes the Establishing a database connection error

To understand what can cause this error, let’s quickly go over what a database is. According to Oxford Dictionary it is as following:

A structured set of data held in a computer, especially one that is accessible in various ways

In practice a database is a piece of software containing data for other software to access and utilize. It can be seen as a well organized file cabinet in an office; a central location to easily store and access information.

As said other software can access this information, including WordPress. For this a database connection has to be set up however, which has failed if this error shows.

WordPress uses its database to store all dynamic content of your site. Think of posts, pages, comments and other data.

To connection to a database WordPress needs the following:

  • Database name
  • Database username
  • Database password
  • Database server

If any of these are incorrect, your connection will fail. Luckily, if you follow our 1 minute WordPress install guide, these details will be entered automatically.

Let’s now go see all the most common problems you might encounter, and how to fix them.

WordPress database login details

Chances are good that when you encounter this error, your credentials are the reason why. Especially when you just installed WordPress, or moved host.

The credentials to your database are safely stored in the wp-config.php. This file can be found in the directory of your WordPress installation.

Once you’ve found this file, open it in whatever editor is supplied. Once inside you’ll want to find these lines.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Once you’ve found them, make sure the data matches what you expect there to be.

In case you don’t know what data is supposed to be here, you can check this with your hosting account. In our case it’s very straight forward to see, so let’s go over that. First lets navigate to our user panel.

Userpanel
User panel

Once you click on “SQL Services” on the left panel you should see a screen that lists all your databases. Here you should make sure that the database listed in your wp-config file is present, and has the correct user assigned.

You can also reset the DB user’s password and note all the details down. Next enter these details in your wp-config.php file, putting ‘localhost’ as DB_HOST when using a shared hosting services as our own.

After following these steps and saving the file you may refresh your site and see if everything works as planned.

Closing words

This error can be extremely frustrating to solve when all you’re trying to do is start work on your site. Hopefully this fix, which is the most common problem, has solved it for you. In case it hasn’t, your next step should probably be to contact your hosting company.

If you have any questions about this topic or need further assistance from us, let us know! You can contact us either through a support ticket or on Twitter. We’d love to hear your thoughts.

Similar Posts

Leave a Reply

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