a

Categories: Blogging WordPress

[Problem Solved] error establishing a database connection in WordPress

WordPress is world best CMS. There are billions of website using WordPress to manage websites. If you have been surfing the web for a while, you have at least seen this error (error establishing a database connection) a few times. Error Establishing a Database Connection is one of those curses that could be caused by many reasons. As a WordPress beginner, this could be awfully frustrating specially when it happened on its own without you changing anything.

You also like to Read…

We ran into this issue yesterday on our own site. It took a little over 15 minutes to detect and fix the problem. While doing the research to find possible causes. I realized that there was no good article that covered everything.

In this article, we will show you how to fix the error establishing a database connection in WordPress by compiling a list of solutions all in one place.

Why do you get this error?

Well in short, you are getting this error because WordPress is unable to establish a database connection. Now the reason why WordPress is unable to establish a database connection can vary. It could be that your database login credentials are wrong or have been changed.

  • It could be that your database server is unresponsive.
  • It could be that your database has been corrupted.

In our experience, majority of the times this error happens because of some sort of server error however there could be other factors as well. Lets take a look at how to go about troubleshooting this problem.

Step 1: Determine Error Establishing a Database Connection

Are you encountering the same error when you try to enter the website URL (front-end), and when you attempt to login to /wp-admin/ (back-end)? If the error is the same, i.e., error establishing a database connection, move onto the next step.

However, if you encounter the following error when trying to login to /wp-admin/, your database has been corrupted:

“One or more database tables are unavailable. The database may need to be repaired”

In your root WordPress file directory, you must locate your wp-config.php file. You must do this to enable WordPress’ built-in repair feature.

Launch Filezilla –> (WordPress install folder) –> public_html

Right-click the wp-config.php file and select a code editor, such as Sublime Text Editor to open the file.

After you’ve opened the wp-config.php file, add the following line at the bottom of the file:

 define('WP_ALLOW_REPAIR', true); 

Now navigate to:

 yourwebsite.com/wp-admin/maint/repair.php 

Replace “yourwebsite.com” with your actual URL

You will see the above-mentioned options. We recommend you to choose the “Repair and Optimize Database” option. Although it takes more time, it is a more comprehensive attempt to fix the issue.

Did this method fix WordPress error establishing a database connection? If so, congratulations! If not, carry on reading this guide to find another fix regarding the error.

Step 2: Check Database Login Credentials in wp-config.php

WP-Config.php is probably the single most important file in your entire WordPress installation. This is where you specify the details for WordPress to connect your database.

If you changed your root password, or the database user password, then you will need to change this file as well. First thing you should always check is if everything in your wp-config.php file is the same.

1234define('DB_NAME', 'database-name');define('DB_USER', 'database-username');define('DB_PASSWORD', 'database-password');define('DB_HOST', 'localhost');

Some folks suggested that they fixed their problem by replacing localhost with the IP. It is common to see this sort of issue when running WordPress on a local server environment.

1define('DB_HOST', '127.0.0.1:8889');

IP’s will vary for online web hosting services.

If everything in this file is correct (make sure you check for typos), then it is fair to say that there is something wrong on the server end.

Step 3: Reset Username and Password

You must ensure that the username and password in your wp-config.php file match the in phpMyAdmin. In our case, it’s “MySQL Access”.

If the username and password do not match, open your wp-config.php file and edit it to include the values from the “MySQL Access” panel. That’s it! If you were attempting to do this via cPanel, you’d have to put in a lot more effort.

I hope you like this article. If yo really like this article please don’t forget to share on your social media accounts. Thanks a lot for reading my article please also give us a like. I also write many articles on WordPress problems and others tips and trick. So if you need updates from my blog please fill the form given below.

[everest_form id=”606″]

Share
Published by

Recent Posts

20 Keyboard Shortcut Keys That Will Make You a Computer Expert
  • Computer
  • Windows

20 Keyboard Shortcut Keys That Will Make You a Computer Expert

Keyboard Shortcut keys help provide an easier and quicker method of navigating and executing commands in computer software. Shortcut keys… Read More

4 days ago
12 Rabi ul Awal Flex Design free Download – Mehfil e Milad Flex
  • Photoshop

12 Rabi ul Awal Flex Design free Download – Mehfil e Milad Flex

Hey Madni Bhai ! Asslam-o-Allaikum. Welcome to my website. First of all many many Happy 12 Rabi ul Awal. I… Read More

1 week ago
Top 5 Affiliate Programs to Make Money Online in 2019 Fast
  • Make Money Online

Top 5 Affiliate Programs to Make Money Online in 2019 Fast

In this Article I will share top 5 affiliate programs to make money online in 2019. These affiliate programs are… Read More

2 weeks ago
How to Save WhatsApp Messages Without Taking a Screenshot
  • Android
  • How to
  • iPhone
  • Latest
  • Mobile
  • WhatsApp

How to Save WhatsApp Messages Without Taking a Screenshot

The Facebook owned messaging app WhatsApp is one of the most widely used messaging platforms around the world. Facebook revealed last year, that… Read More

2 weeks ago
Best WhatsApp Live Translator – Translate your Friend Messages from his Chat
  • Latest
  • Mobile
  • Tips & Tricks
  • WhatsApp

Best WhatsApp Live Translator – Translate your Friend Messages from his Chat

Best WhatsApp Live Translator. Hey there in this post I'll tell you how to put One Tab translator in WhatsApp.… Read More

3 weeks ago
WhatsApp Will Dance After Receiving Notification OR Message
  • WhatsApp

WhatsApp Will Dance After Receiving Notification OR Message

Your WhatsApp will dance after receiving notification OR message on your number. New WhatsApp secret trick 2019. Before I start,… Read More

3 weeks ago