Bh Rubel

Learn and Be Succeed

Fix the Error Establishing a Database Connection in WordPress

I think you are suffering from a problem with your web site Error. What kind of error occurred on your site? Is it ” Error Establishing a Database Connection” error?

If it is ” Error Establishing a Database Connection” error. It has shown a message like:

Error Establishing a Database Connection

Error establishing a database connection

Understanding the Problem

Do you know why the problem occurs?

WordPress uses two main pieces of technology. One is PHP, and another is MySQL.

PHP is a programming language. The core files of WordPress have written in PHP. MySQL is a database technology in which all of the content of your website store. PHP is used commands to connect WordPress to the MySQL database, getting information, and then display everything on the screen.

When any kinds of error occur in the database, WordPress can’t access to the database using PHP. Without showing anything on the screen, it shows “Error establishing a database connection.” It often occurs when database credentials are wrong or have been changed. It also happens if your database has been corrupted. Too much traffic may be a reason for this error.

How to Fix ” Error establishing a database connection”

In this tutorial, we will try best to give a better solution to this problem. Don’t worry, read the whole article, and remove your panicking.

Do you notice this error on both the front-end of the site and the back-end of the site(wp-admin)? You may see the same error message “Error establishing a database connection”, and may get a different error message on the wp-admin, for instance, something like ” One or more database tables are unavailable. The database may need to be repaired”, then you need to repair the database. If the error message is the same on both pages, you need to jump the next step. If it shows a different error message on the wp-admin page, you may repair the database by adding the following code in your wp-config.php file just before ‘ That’ all, stop editing! Happy blogging’ line.

1 । define (‘WP_ALLOW_REPAIR’, true);

Doing that you can visit this page: http://www.yoursite.com/wp-admin/main/erpair.php

You will see like:

Automatic repair database error

Once the automatic repair finishes, refresh your site and if the error still there. If there is no error, it is great for you. Then you need to back your “wp-config.php” file and remove the line that you just added update the file.

Checking your WP-config file

WP-config.php is the most important file in your WordPress installation. This is where you store all the information to connect your database. For any reason, you changed your root password or, the database user password, then you will need to change the file as well.

Then you will need to check your config file and, there you will see the same like:

define(‘DB_NAME’ ,’database-name’); define(‘DB_user’ ,’database-username’); define(‘DB_PASSWORD’ ,’database-password’); define(‘DB_HOST’ ,’localhost’);

DB_host will be different depending on the host. For popular host like HostGator, BlueHost, SiteGround, it is localhost.

Check your Web Host (MySQL server)

A lot of traffic may cause this error. Any post of your site might be viral, as a result, you might get a lot of traffic. Your server can not handle the load. Your site might have slow and some users see the error on their device. So it is the best solution for you to contact your hosting provider and ask them if your MySQL server is responsive. If there has any problem, they can help you solve the problem.

If you want to solve the problem yourself, then you may start. First of all, you have to test other sites on the same server to see if they have any issue. In case, you have the same error, then you may be sure that there is something wrong with your MySQL server.

If you don’t have any other site on this same hosting account, then go to your cPanel and try to access phpMyAdmin and connect the database. After being successful to connect, you need to verify if your database user has sufficient permission. Creating a new file called testconnection.php paste the following code in it:

<?php $link = mysqli_connect (‘localhost’, ‘username’, ‘password’); if (!$link){ die (‘Could not connect : ‘ . mysqli_error()); } echo ‘Connected successful’ ; mysqli_close(‘$link’);

After replacing the user name and password, if the script connected successfully, you may realize that there is something wrong. Revert your wp-config file to make sure that everything there correct.

If you fail to connect to the database by going to phpMyAdmin, you may be sure that it is something wrong with the server. It means that your user does not have sufficient permission. Take your phone contact your host provider or live chat with their supporting foram and get the proper solution.

Restore The Default WordPress File to Error establishing a database connection

The core files of WordPress can be corrupted in many ways. Maybe you modified some files accidentally, or maybe you added some rogue plugins which are the cause of the error. Many corrupted people attempt to hack your site and make some modification for your site.

You can restore the fresh core WordPress files. To restore the files you need to download the fresh WordPress package to your desktop and unpackage the WordPress file. Then you upload the files of WordPress without wp-content folder. If there is any problem in the core files, it will be fixed.

Popular Posts