Fix Error Establishing a Database Connection in WordPress

Recently i was trying to install WordPress on my friend’s localhost but an error occurred which said – “Error establishing a database connection in WordPress“.

I’ll not go in detail, lets just solve the error right away. In order to fix – Error establishing a database connection, you’ll need to follow two steps.

  1. Creating a new Database
  2. Creating Database User
  3. Editing wp-config file of your WordPress package.

Where to Find wp-config file?

If you plan to install WordPress on Local Host using WAMP server then wp-config file has to be inside www folder (C:wampwww). If you plan to install WordPress on Web Host then you can access wp-config file using FTP Client like FileZilla.

You need to know the right location of wp-config file in order to proceed. If at all you have any difficulty to find wp-config, just leave a comment below and i’ll surely help you out.

Step 1 – Creating Database

Step 2 – Creating Database User

  • If you are installing WordPress on Local Host then just go to step 3
  • If you are installing WordPress on Web Host then read THIS article.

Step 3 – Editing wp-config file

When you open wp-config file, you’ll see something as shown below.

WP Local Host Installation

If you have created database named XYZ then make the following changes in your wp-config file –

WP Web Host Installation

If you have created database named ABC and created a user with username: admin and password: hello then just make the following changes in your wp-config file (which is on the server).

Long Story Short

You need to create database and database user. The database user will have username and password. This error usually occurs because of mismatch in configuration. So to fix it, open wp-config file and enter the right database name, database username and database user password. Save the file where it is supposed to be. And problem of “Error establishing a database connection in WordPress” will be solved.

Thanks for reading and do subscribe to blog feed for more amazing posts. You can find the subscription box below.

Adding User To MySQL Database In Linux Hosting

In the previous post, I have written about creating a MySQL database using control panel in linux hosting. Now lets see how to add users to the newly created database.

Here, two steps are involved. First is creating the user and second is adding the user to the database. So lets see how to do that.

#1. Creating MySQL User

  1. Login to your webhosting account.
  2. Go to control panel (cPanel).
  3. Select MySQL Databases
  4. Scroll down to MySQL Users
  5. Type in the desired username and password in the input form.
  6. And click on create user.
  7. This will create a new MySQL user.

But not that, this newly created MySQL user has no access to any MySQL database. So to associate this MySQL user to any database you’ll need to follow step 2.

MySQL Database

#2. Adding MySQL User To MySQL Database

Once you create a new user, stay on the same page and scroll down. You can see Add User To Database option. This is where you will have to select the User and select the Database from a drop down menu. After selecting the user and database, just click on Add button and you are good to go.

You can now use this newly created database for installing WordPress, Joomla, etc.

Creating New Database Using MySQL In Linux Hosting

In this post, I’ll be talking about how to create a MySQL database in Linux Web Hosting. This is actually very simple. First of all, login to your hosting account and open the control panel (cPanel).

In cPanel, navigate or scroll down to the databases section. Here select the MySQL databases option. And rest you can figure it out yourself. But if you can’t, then continue reading..

You can find a box which says ‘Create New Database‘. All you need to do over here is just enter the name of the database. And hit the ‘Create Database‘ Button.

Your database will be created. You can now use this database for WordPress, Joomla, etc. But you’ll need to add users to the newly created database. In the next post we’ll see how to add users to the MySQL database.