How to Fix the WordPress Error Establishing a Database Connection – Meaning [Infographic]

Fix the Error Establishing a Database Connection

If you cannot see your website’s home page showing the message “Error Establishing a Database Connection” in GoDaddy/Bluehost/Hostgator, it appears that there exists a fatal error that makes your website pages inaccessible to the user. WordPress beginners probably get a bit scared right now looking for its meaning, but let me assure you that this database connection error problem can be fixed very easily irrespective of your hosting in Godaddy or Bluehost. In fact, many of the WordPress users might have seen the error establishing a database connection in GoDaddy at some point in their life. Often we will see such errors at the starting point of WordPress installation in GoDaddy, Bluehost, or any other web hosting platform. As I shifted my blog hosting to a reliable hosting company, I did not face any such database issues with a new host.

No need to be panic. Whatever is your hosting, let us check the causes of such DB errors. Most probably, it will be just a configuration issue that can be solved quickly.

[Note: Infographic link is given at the bottom of this article]

Fixing WordPress Database Error for GoDaddy and Hostgator

The error establishing a database connection in WordPress occurs when the files in your hosting are unable to make a connection to the database. In fact, there are a number of things that can cause WordPress database connection issues which we will learn in this post.

Note: If you are just about starting a new blog, it is very important to have a perfect blog theme from the very beginning. Consider reading the best five WordPress blog themes to get your right theme. And if you are a girl, do not hesitate to check the high performing feminine themes which many successful female bloggers are using now.

What is the meaning of “Error Establishing a Database Connection”?

error establishing a database connection in Godaddy hosting

Let us first understand how the website is functioning and then it will be clear to you what this database error is.

The WordPress website is operating using PHP and MySQL database files. All the information which we enter into the site is stored in the database. The PHP files store and retrieve that information to display the site pages. When the website pages start loading, the PHP queries begin to retrieve the information from the database and grab the details such as post title, author name and publication date, etc.

So when an error message is displayed as “Error establishing a database connection”, it means the PHP files failed to retrieve the data stored in the MySQL files for some reasons while trying to build the page. When it cannot build the page, it is evident that only a blank page can be displayed with an error notification.

In this article, let’s learn how to quickly fix the error establishing a database connection in the WordPress website hosted in any platforms like GoDaddy or Hostgator. Just follow these steps to get your database reconnected and your website running smoothly.

What Causes the ‘Error Establishing a Database Connection’?

There can be many reasons for PHP – MySQL connection issue, but, they can generally be categorized into three types:

  1. Your login credentials for your database are incorrect – The database credentials existing in the PHP files are not matching with that of the MySQL database. Any error or mismatch in the credential details can cause a fatal error.
  2. WordPress database is corrupted – WordPress database may be corrupted while changing or entering the data through any attempts such as uploading a bad plugin to lightning strikes to the server.
  3.  The server of the database is down – In this case, your hosting has got some error due to some technical problems on the hosting company end or your website has experienced huge traffic that the hosting bandwidth could not handle.

So with all these possibilities, how can you narrow down the causes and fix the database connection errors in all kinds of hosting (Hostgator/GoDaddy/Bluehost/Hostinger, etc)?

1. Identify the Kind of Error Establishing the Database

Sometimes you will be able to see the site loading normally and get the error only when you try to access ‘wp-admin’. Or maybe, you are seeing some other error messages like “One or more database tables are unavailable…”, while trying to login. This indicates that your database got corrupted.

WordPress can try to repair your database if you enable a feature by entering a piece of code manually. For this, you need to access the root folder and edit the wp-config.php file.

accessing wp-config file for checking database errors

Once you could get the files on the edit mode by clicking on it and selecting ‘edit’ option, add this line of code to the bottom:

define( 'WP_ALLOW_REPAIR', true );
 
If you have done it, you can move to this URL www.yourwebsite.com/wp-admin/maint/repair.php (just replace “yourwebsite.com” with your own site URL).

Repairing Error Establishing a Database Connection in GoDaddy

You will get two options as seen in the above image where you can choose one of them that you feel comfortable selecting, noting that optimizing the database might take longer. Once you have done the troubleshooting, you need to remove the piece of code you have just added in order to block anyone else from messing with your database.

If this way of identifying and fixing the error doesn’t apply to you, move on to the next step to continue troubleshooting.

2. Check Database Login Settings in wp-config

The next thing we can do is to check the database login credentials existing in the wp-config file at the root folder of the hosting.

There can be a few reasons why the login credentials existing in the wp-config may not be correct. If you have changed the domain/hosting provider recently or changed any of the credentials at C-panel, the database name and login name in wp-config have to be updated.

You should check the credentials in wp-config and compare it with the actual login details from your database details in C-panel.

// ** 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' );

 

The following details you will find in the file and it has to be re-checked and updated.

  1. The name of the database (“DB_NAME”)
  2. The login username (“DB_USER”)
  3. The login password (“DB_PASSWORD”)
  4. The database host (“DB_HOST”)

If one of these values is not the same as the actual, WordPress cannot connect to the database resulting in an error establishing a database connection.

Test your existing login credentials

You can create the existing login credentials by following the troubleshooting method.

Just create a PHP file with any name say testconnection.php in the root folder and paste the following code on it.

Then search for the URL (e.g. your site.com/testconnection.php). You’ll get either a successful connection message or an error with more details.

?php 
$test Connection = mysql_connect('localhost', 'root', 'password');
if (!$testConnection) {
die('Error: ' . mysql_error());
}
echo 'Database connection working!';
mysql_close($testConnection);

If the username and password aren’t working, you can create a new one from the hosting panel as follows.

Generating new credentials to fix the error establishing a database connection Godaddy and Hostgator

From the C-panel navigate to “MySQL® Databases”. Clicking on it will give the different databases existing on the hosting with its user’s details. You can either create a new user and add it to an existing database or change the existing password. Or even change the database name there. Update your wp-config file with the new username and password which you have created.

Another important thing that we usually forget to check is the hostname in the ‘wp-config’ file. In most cases, the hostname is ‘localhost’ but for many other hosting providers it may vary depending on their server configuration. Either you can contact your hosting company to ask what value to use or do a Google search to find the database hostname of the service provider. Once you got the correct IP, change the data ‘localhost’ to the server’s IP address.

3) Other Solutions That Have Worked for Users in Fixing the Error Establishing Database Connection Issues

You can also try the following steps that might help to fix the database connection issue.

A) Update WordPress Site URL in phpMyAdmin

Try updating the WordPress site URL and home URL using phpMyAdmin. Simply access phpMyAdmin from your hosting account dashboard, and click on ‘wp-options’. Just clicking at the existing URLs, it will become editable for you to update it with your correct website URL as seen below.

updating the WordPress site URL using phpMyAdmin for fixing database errors in Hostgator/Godaddy

B) Rebooting Website Server

Restarting or rebooting the VPS (virtual private servers), dedicated servers, or the local servers can help to clear any temporary glitches causing the error.

C) Ask for help

You can also hire WordPress developers from Upwork or Codeable or any other similar platforms to get the help to fix this issue for reasonable rates.

4. Check with your hosting company

Even after you have followed the above instructions, your website is still showing the database error message, then it could be a problem on your website host’s end. Contact your web hosting company’s technical support (GoDaddy/Bluehost or Hostinger) either through a quick chat or a phone call and provide all the details of the error and the troubleshooting steps you have already taken, and they may be able to fix the error establishing a database connection in your WordPress website. If the error still continues as such consider changing your web hosting to a more reliable hosting with an efficient chat support team. I recommend this Hostgator as I know that even if you ask the chat support about a database error that is not related to your hosting, they will most likely give you technical advice to fix it quickly.

 

You May Also Like

About the Author: BW

7 Comments

  1. Pingback: How to Set Up WordPress Error Logs in WP-Config - Manual & Plugin
  2. Pingback: Replace Old URL with New URL in Revolution Slider Banners - Free Ways!
  3. Pingback: How to Fix Database Link Errors in WordPress ~ Solutions
  4. Pingback: Changing Your WordPress Database Prefix to Improve Security ~ Guide
  5. Pingback: How to Get WordPress Username and Password From the Database
  6. Pingback: WordPress Change Site URL Using MySQL Query When Site is Moved
  7. Pingback: How to Export Database From phpmyadmin? | Export Database

Leave a Reply

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