How to Fix The Error Establishing a Database Connection in WordPress

Error Establishing a Database Connection

Are you tired of facing the problem “Error Establishing a Database Connection in WordPress”? It is one of the fatal errors that stop people from accessing your website. 

It can be very much troublesome for beginners to troubleshoot this common error. Besides, if you do anything wrong, your database can be lost along with the database. So, What is the solution to this problem?

Well, to solve this problem, stop panicking. Stick to the post till the very last, and then you will be able to solve this problem all by yourself. 

Let’s start, then. 

What Can Cause An Error Establishing A Database Connection In WordPress?


Fix The Error Establishing a Database Connection in WordPress

To fix this problem, you should take these measurements one by one. One of the following should fix your problem. 

1. Check Your WordPress Database Credentials. 

Having the wrong database credentials is the most common reason for database connection errors. All your credentials are saved in the wp-config.php file. In this file, the important configuration is saved, including database information. 

When you see the error, open the wp-config.php file and search for the following 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' );

Now, make sure your username, password, database host, and database name are correct. You can check and confirm this from your hosting dashboard 

Navigate to your hosting dashboard and then click on MySQL databases. The database management page will be opened, and from there, you will find out the username and database name. 

Then, you have to look for the database users and links to change their passwords. 

When you have found the username, database name, and password, you can change the required information in the wp-config.php file. After that check your website if the error is solved. 

2. Check For Your Database Host Information

After making sure that your username, Database name, and password is correct then you may review the database host information. 

A lot of hosting companies use localhost as database hosts. However, some companies may use separate servers to host databases. So contact your hosting company and confirm your database host information. 

3. Repair Your WordPress Database

If you are having a different error, like ‘one or more database tables are unavailable, then your database might need to be repaired. 

All you have to do is add a simple line in your wp-config.php file. Open the wp-config.php file and add the following line. 

define('WP_ALLOW_REPAIR', true);

Then, enter the following link, and you will see the repair option. Don’t forget to replace the link with your website link.

After you are done repairing, remove this code and save the wp-config.php file. 

4. Check For If The Database Server is Down

If everything seems fine, then your MySQL or database server might be down. This might happen to heavy traffic on your server, especially when you are using any shared hosting server. 

For this reason, some users may get errors, and your site might get slow. So the best way is to make a phone call or knock on the support of your hosting provider and ask if your Database server is responsive. If there is any problem, ask them to fix it. 

Last Words

The above reasons are the most common ones for the problem “Error establishing a Database Connection in WordPress’. There might be other reasons for arising this problem, but those are very rare. First, try to apply the above solutions. If the problem is still not fixed, call a developer to fix the problem. 

If you like this post, please share it with your friends, and don’t forget to leave your thoughts in the comment box below. 

Leave a Reply

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

Need help?