BloggingBIG Logo
Search
  • Blogs
  • How we work
  • Write Guest Post
Get started

5 ways to Fix Error Establishing a Database Connection

by Raju Khadka

  • 8 min read
    • SEO
Share this content
5 ways to Fix Error Establishing a Database Connection image

Right now are you getting error establishing a database connection in WordPress? I know its too frustrating error.Here, you will learn how to fix that easily

Navigation

  • What is database connection in wordpress
  • What does Error establishing a database connection mean?
  • What Causes The”Error Establishing A Database Connection” Message to show in browser
  • How to troubleshoot WordPress Error Establishing a Database Connection?
    • Fix 1: Contact your Hosting Company to know if Error is from there end
    • Fix 2: Check Your Database login details from wp-config.php
    • Fix 3: Check If You Can Still Access The WordPress Dashboard or not
    • Fix 4: Fix to Make Sure Your Plugin or Theme Files aren’t Corrupted
    • Fix 5: Restore The Default WordPress Files

What is database connection in wordpress

database connection is a means by which you can access the server programme whether on the same machine or the different machine.

What does Error establishing a database connection mean?

whenever you try to acess the website php program tries to connect to the database and from there it loads the content you trying to access.


Error Establishing A Database Connection

But, if you see something like error establishing a database connection it means php program is not able to connect to db(database).

Because of several reasons like : username and passord not matching,server error etc…

What Causes The”Error Establishing A Database Connection” Message to show in browser

there are actually several reasons to show these kinds of DB errors connect failed scenario they are :

1. Hosting Error from the hosting company

2. failed to connect to mysql database

3. User and password are not matching in wp-config.php file

4. Your themes or plugins are corrupted

5. All your WordPress files are corrupted

In such situations, you will be connected to internet but cannot access websites its either an error from your end or its form the server end. so how to fix website which are showing those errors

How to troubleshoot WordPress Error Establishing a Database Connection?

Here I am assuming that you are using WordPress CMS.We can solve that wordpress connection lost errors.

Fix 1: Contact your Hosting Company to know if Error is from there end

This becomes the first step for you to take coz if those errors are form the hosting company side why to start making changes from your end and waste your time .

So, my first suggestion would be, to contact your hosting provider from the live support section and let them know that you are facing some WordPress database error

Then they will let you know if its a problem from there end or it’s from your end.

Now after they fix the error try to access your site from the browser if still shows same error connecting to mysql ( i means same previous error establishing database connection )

then move to the second solution

Fix 2: Check Your Database login details from wp-config.php

Another possible reason could be that your username and password may not be matching which you can easily fix from the wp-config.php

To fix this way you need to have your cpanel details to access wordpress database.

How to know that cpanel details?

You need to see the initia l emails from your service provider they will give you the cpanel details in the mail.

otherwise, in some hosting, you can also access the cpanel from their website client area which details are the details you used to register in their website before buying hosting service.

Now, I assume that you are in your cpanel

my hosting company’s client area

Now, after that I am gonna click on the file manager and i will enter into the Cpanel. After that I will get some screen like this:

cpanel for fixing website db error

now, double click on the left side : public_html

After that find out wp-config.php

now you will see this

/** MySQL database username */
define('DB_USER', 'username');

/** MySQL database password */
define('DB_PASSWORD', 'password');

In this area, if the WordPress username and password are not being matched then it shows that error connecting to MySQL establishing connection error

Now:
How to fix this password error ??

for that go back to the client area
as shown in the figure to access the wordpress database

How to access wordpress database?



Now, this time click on the MySQL Database:

After clicking on the database you will see the UI like this:

from here you can create new user and password
Take care of the username and password you put and generate here coz these are the one you put in wp-config.php

if you have created the new user then you need to activate that user by giving all the privileges, If you feel confused just change the password from same MySQl Database section . these options are just below the creating new user option as shown in figure :

now again go to file manager from the client area

/** MySQL database username */
define('DB_USER', 'username');

/** MySQL database password */
define('DB_PASSWORD', 'password');

and here replace the username and password

Now try to access the website from the browser If you are able to access it then problem is solved. If not go to the 3rd solution

Fix 3: Check If You Can Still Access The WordPress Dashboard or not

So the now next solution is to see if you can access your wordpress dashboard or not.

remember this : wp dashboard login details and the database username and password are different.

At the time of installing wordpress you will have to choose username and password this is the same username and password that are used for logging in wp dashboard

at the time of accessing the dashboard if you see some error like this:
“The database may need to be repaired”

You need to repair your database now .
now :

Step 1: mysql repair database (db)
To repair my sql database you need to again go the the same file manager as done in above scenario

Now, go to the public_html>>doubleclick it >> wp-config.php>> edit it

Trying to repair myql database to fix wp error

now after you click edit go to the bottom and add following code:

 define( 'WP_ALLOW_REPAIR', true );

click on the save change

Step 2: Run the automatic database repair utility.
Now go to :

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

after this you will be able to run a tool which repairs your database

repair-database-wordpress

after this hopefully, your site should start working. What if didn’t work again? I have still 2 more options left.

Fix 4: Fix to Make Sure Your Plugin or Theme Files aren’t Corrupted

This is the next step you can carry out to fix wordpress database

for this, again go to the file manager as in the previous steps

fixing wordpress databse errors by checking if Plugin or Theme Files aren’t Corrupted

troubleshoot wordpress website for error establishing a database connection by renaming

Now, go to the public_html>>click on + sign>>wp-content>>plugins
after going there you will see the plugins that are installed in your website.

sometimes those plugins and themes cause to happen error establishing a database connection in wordpress install time.

now as in the figure above you are seeing that the name of the plugin I have renamed from askmit to askmit_ replaced by (underscore )
do this

Keep coming back to your site to see when the error gets triggered or vanishes. Once you’ve narrowed it down to one specific plugin, you have found the troublemaker.

Either delete it or go online to see if the solution has been found.

repeat same for the theme also .. change the themes to themes_

and try to check by going to the browser if it gets the db errors solved.

if it didn’t solve now rename back to the previous names.

Fix 5: Restore The Default WordPress Files

caution: before doing this take all the backups of your file: otherwse don’t blame me since this is the last option.

go to worpress officil site :

wordpress official site

download it,

extract it ,

upload all the new files upload it from the cpanel once again

go to the file manager as previous and at the top, you will see the upload option upload the new and fresh version of your WordPress and try to see if it solves your problem or not.

Let me show you what has worked for others :

fix wordpress database error

fix wordpress connection lost

fix wordpress error establishing a database connection

found new solution to error establishing database connection

solution for wordpress establishing database connection

wordpress database error troubleshoot

Last option: Again, go to your web hosting and then tell them what and all efforts you have put to fix errors and tell them to fix it from their end

And say them it’s not possible form your end

As i know how hard yo have done and you might have gotten frustrated by this time.

after all you have paid them your hard earned money right?

if they are not fixing it it means they are not good hosting providers,

who knows what other problem you may get in future so choose another best hosting as fast as possible.

One last word : Are you a bloggers ? subscribe to this blog and lets grow together .

If this helped you why not to share with other show your followers that you care of them by sharing the content they may love ; sharing is caring

 

Other articles to read for you:

https://www.old.bloggingbig.com/best-seo-plugins-for-wordpress/

Share
Tweet
Share
0 Shares
Raju Khadka image

Raju Khadka

I crawl possibility Index opportunity Interlink feasibility & develop personal authority. 😃 Could not figure out what my bio means? if so, you still need to learn SEO. Keep checking my SEO post in Blogging BIG

Be first to comment

Leave a Reply Cancel reply

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

More from SEO

FREE Website SEO Audit for Nepali Local Business in 2022 image

FREE Website SEO Audit for Nepali Local Business in 2022

Raju Khadka image

by Raju Khadka

  • 1 min read
    • SEO
#1minuteseotips [Best SEO Tips For Blogger in 2021 ] image

#1minuteseotips [Best SEO Tips For Blogger in 2021 ]

Raju Khadka image

by Raju Khadka

  • 43 min read
    • SEO
Signup for web hosting giveaway image

Signup for web hosting giveaway

Raju Khadka image

by Raju Khadka

  • 0 min read
    • SEO

Quick links

  • Siteground black friday deals
  • Wp engine black friday deals
  • Greengeeks black friday deals
  • Tmd hosting black friday deals
  • Fastcomet black friday deals
  • Hostwinds black friday deals
  • bluehost black friday
  • Namecheap black friday deals
  • Ionos 1 & 1 black friday deals
  • Hostgator black friday deals
  • ipage black friday deals
  • wpx hosting black friday deals
BloggingBIG logo
  • About
  • DISCLAIMER
  • Disclouser for Blogging BIG
  • Terms and Conditions
  • Privacy Policy
  • Sitemap
Developed by Fnclick
Back To Top