How to Fix Error Establishing a Database Connection in WordPress: Knowledge is power, one of the most frustrating issues you might come across in wordpress is the “error establishing a database connection” nevertheless I am here with a solution on how to fix this error. New to my website? My name is yanke I am dedicated wordpress solution solving blogger and I always tutor my site users on how to go about their wordpress blog.
Are you currently seeing the error I mean are you having an error issue relating to the topic “Error establishing a connection”? If yes then I have got the solution for you. This error is a fatal error that makes your wordpress website inaccessible to the users. This error only occurs when wordpress is unable to make a connection to your database.
In this article I would show you how to successfully fix this error.
Let get started.
First let’s look at the causes in other to avoid it next time.
This error issue can be caused by incorrect database information in your wordpress blog settings, either corrupt database or an irresponsive database server.
What is a database: database is software which makes it easy to store, retrieve and organize data info into other software/program.
WordPress is a content management system (CMS) and it uses a database in other to store all contents and other website data. It connects to the database each time a site user visit your wordpress blog/website.
In other to connect to the database your wordpress site needs the following information:
- Database username
- Database name
- Database password
- Database server normally “localhost”
This info’s is stored In your wordpress configuration fill known as “wp-config.php”, if any of the mentioned items are incorrect wordpress would fail to connect to your database, which would result to an error establishing a database connection message”.
These errors can also be caused by a database server downtime or corrupt database.
In this article I would be explaining how to fix this error with a step by step troubleshooting.
Step 1. Check if wordpress database credentials are in correct.

Incorrect credentials are one of the most common reasons for database connection error. If you recently moved your wordpress blog to a new host this can likely be the reason.
Database credentials are normally stored in the wp-config.php file. This is the wordpress configuration file that contains all important wordpress settings including your database information.
If this is your first time editing a “wp-config.php” file then you have be very careful while editing.

Login to your control panel and locate where your wordpress files where installed, navigate to the wp-config.php file and locate the following codes shown below.
// ** 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' );
Run a check on the database name, username, password and database host make sure it’s correct.
You can confirm this information for your wordpress hosting account dashboard. Login to your hosting account and locate the MYSQL database. This will take you to a new screen displaying the database management page in your hosting dashboard. On that page you can find out your database and username. You can change your user password over there then return back to the “wp-config.php” file and fill in the new password.
Make sure to save the config.php file then try loading your site again.
If you still seeing the error then that was never the issue.
2. Run a recheck on your database host information.
Let’s check if the database host information is correct as well. 99% wordpress hosting companies make use of “localhost” as your database host. How er some companies use separate serves to host databases. In that case your database host will not be localhost. Best way to figure out your hosting database host is to contact your hosting company in other to confirm your database host information. If you using namecheap, bluehost or godaddy then “localhost” is certainly your database host.
3. Repair your wordpress database
In this case if you getting a different message entirely on the wp-admin dashboard for instance message related to “one or more database tables are unavailable. The database may need to be repaired, meaning you have to repair your database. You can resolve this by adding the following line in your wp-config.php file. Make sure to add it.
define('WP_ALLOW_REPAIR', true);
Once you done you should see the settings by visiting the page of your website: http://www.yoursite.com/wp-admin/maint/repair.php
You do not need to be logged in to access the database repair page. Once repair and optimization are done, make sure to remove the code you recently added from your wp-config.php.
4. Run a check if your database server may be down
If after running all first three methods and wordpress till cannot connect to the database, then your database server (MYSQL sever) may be down.
This normally occurs when there are heave traffic on a server. In other words this means your host server just cannot handle the load most especially if you on a shared hosting plan.
The best solution is to get your phone call place a call to your hosting customer care or live chat with your hosting provider and ask them to help fix or run a check on your “MYSQL” server or ask if it’s responsive.
If you have other sites running on same server/host then you can as well run a check on those sites confirming if your SQL server is down. If this other sites hosted on your servers are showing same errors then it means your SQL server is down.
.if you do not have any other sites hosted on the server then simply go to your hosting account dashboard and try accessing “PHPMYADMIN” and connect the database.
If you can connect, then we need to verify if your database user has sufficient permission. Create a new file called testconnection.php and paste the following code in it:
<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>
Make sure to replace the username and password. You can now upload this file to your website and access it via web browser.
If the script works or connected successfully, then it obviously means that your user has sufficient permission, something else is wrong.
Return back to your wp-config file to make sure that everything is in perfect order. Make sure to re-scan for typos.
These are other solutions that have worked for me before.
- Try updating your wordpress site url
- Try rebooting your web server
- Ask for help by contacting your host provider.
Follow Ideasgist Now on Facebook and Twitter. Also join in for Latest News, Tech News, Media and lot more.