Tag Archives: wordpress tips hosting

ByAlexia Pamelov

How to Fix WordPress Error Establishing a Database Connection Issue

CheapWindowsHosting.com | Best and cheap WordPress hosting. The Error Establishing a Database Connection is an issue that you may have suffered more than once when surfing the Internet. Since this common error has gotten a lot of webmasters in trouble, we make this guide on how to fix WordPress Error Establishing a Database Connection. Before everything, let’s have a quick view on what the issue is and why you get it.

The Error Establishing a Database Connection is a common issue that has happened to a large number of WordPress websites, which means WordPress cannot establish a database connection on the local host. Once suffering this error, your website is down as well. Meanwhile, you will lose more and more traffic thereby taking a knock from the disaster.

Best OFFER Cheap WordPress Hosting ! Click Here

The main reasons that cause such common error are: You may have added extra space to the username, database name or password; your database login authentication has been changed without your permission; the database has crashed or unresponsive; or something more that has not been detected. No matter which reason brings trouble to you, you can refer to the following terms of settlement to make a hit.

Enable Automatic Database Problems Repair

In addition to suffering this error on the website front end, you may probably run into the same issue on the website back end. If this is the case, you are required to fix the problems that occur to the database. In fact, WordPress enables automatic database problems repair, which helps you fix the Error Establishing a Database Connection with ease.

Go to http://yoursite.com/wp-admin/maint/repair.php and copy & the given shortcode into the wp-config.php file.

define('WP_ALLOW_REPAIR', true);


If you has installed WordPress via control Panel, then you need to log into cPanel and go to Files > File Manager. Pitch on Document root for your website and click Go button to access to the File Manager interface. Find out wp-config.php file from a list of options and add the above-mentioned shortcode to this file. Once saving all changes, you need to go to http://yoursite.com/wp-admin/maint/repair.php again and then the page should be like the following screenshot.


Click the Repair Database button as required and check if there is any problem with the database. This process will take you a while and then presents the checking results to you. If there is a need to optimize the database, you can click the Repair and Optimize Database button to achieve the goal. However, if this method doesn’t work, you need to turn to other solutions.

Fix Database Login Credentials

The wrong database login credential is also a reason to Error Establishing a Database Connection issue. To check if there is something wrong with the database login details, you are required to open the wp-config.php file and focus on database username, password, hostname and some other details, which should be like the following screenshot. The extra space and spelling mistakes are the main causes that make database unable to connect to the local host.

define("DB_NAME", "Your DB Name");
define("DB_User", "Your DB User Name");
define("DB_PASSWORD", "Your DB Password");
define("DB_HOST", "Your DB Host");
define("DB_CHARSET", "Your DB Charset");

 If everything is correct, you should turn to the code define(‘DB_HOST’, ‘localhost’);. The ‘localhost’ can be changed to your host’s value. However, if your website is developed with asphostportal.com the localhost is fine for you.

In most cases, the database address is also the IP address. Thus, you are able to replace the ‘localhost’ to IP address.

define('DB_HOST', 'your IP address');

Reset Database User

If the MySQL database user privileges are limited, then the database cannot connect to the local host. The unique way to solve this problem is to reset database user information, including username and password. Log into cPanel > Files > File Manager and find out wp-config.php file. And then, replace the existing database username with a new one and reset the password as well.

Check the Web Host MySQL Server

Since the MySQL server is overloaded too much traffic, then the server may not be responsive. It commonly happens to the websites hosted on shared hosting solution. Thus, if you are running a large website and keeping up-scaling it, you need to turn to a VPS hosting solution or dedicated server.

Besides, the most convenient way to solve that issue is to contact your hosting provider and ask if your MySQL server is non-responsive. If so, the web host may help you solve the problems as soon as possible.

However, if you want to deal with the error by yourself, then you can log into cPanel and create a new file via phpMyAdmin. Name this file as whatever you want and make it in .php extension. And then, you are required to copy and paste the following code to the newly created file.

$conn = mysql_connect('localhost', 'root', 'password');
if (!$conn) {
die('The database cannot be connected with the exception: ' . mysql_error());
echo 'The database is connected successfully!';

After saving the file, you need to check if runs well by entering the URL http://yoursite.com/thenewfile.php. If there is a successful connection message shown to you, you have fulfilled the task.