Home / WordPress / How to Fix the Error Establishing a Database Connection in WordPress

How to Fix the Error Establishing a Database Connection in WordPress

Any error is a great panic for anybody. An error can eat up your valuable time and make do a critical labor. If you are a website owner, you must have faced some frequent errors while entering into your site. It will happen just when you are unable to organize your website properly. Here is the solution, make a neat web and become tension free. But how? Don’t panic with your errors. In this article, I will be showing why this message appears and how to fix it.  The solution for error establishing a database connection is very easy if you become a little bit conscious about your configuration of your WordPress website.

 

Error establishing a database connection

What is Actually Error Establishing A Database Connection ?

“Error establishing a database connection” means an error message while trying to access to a disorganized website provided by the server. It is a matter of Database. So, you now get a conception of which you are getting this bug. You input your domain name in the address bar, but the browser is responding showing this error message. It is not the fault of your browser rather database corruption. However, to solve this problem, we must have some basic knowledge of WordPress.

 

Use Of Database And Language WordPress

There are several CMS in online market, but most of the domain owners prefer WordPress as CMS (Content Management System). Because of the easy and comfortable interface, WordPress is a popular CMS. However, as we know without a language and database, no website can exist. There are several languages for a website such as HTML, HTML5, PHP, etc. And MySQL is a database.
WordPress uses MySQL as database and PHP as it’s language. If you fail to mix both of them properly, you will notice this error message frequently. So, it goes without saying that you must make a proper connection between this language and database.

Causes of this error message (Error establishing a database connection)

The possible causes are given below. Take a deep look at this causes and solutions to make your WordPress website rock.

  1. Disconnection of MySQL and PHP language : You might have done all the connection while starting your WordPress site. But you may change your DB name and Password for your privacy. And so, now the database is disconnected from your server. Because there is a mismatch in details provided in the wp-config file and the actual DB details. However, this is considered the main reason for getting error establishing a database connection message. That means your ‘wp-config’ file is not accurate. Your cPanel-file manager contains this wp-config file.
  2. Website Database corruption : It is another major cause as there may be data mixing up with unusual systems. It is the disallowing of repair system that is defined in Word Press.
  3. Hosting down : Whatever hosting plan you are using it must load the website fast. Shared hosting usually has some issues while loading the websites. If there is an overload of your website traffic you may face this error message. Your massive traffic may eat up your bandwidth. Then web site database is unable to retrieve any information to show. In shared hosting, you only get a small bandwidth, so it gets used up within a short time.
  4. Old Plugins : You may be using some fantastic plugins for your own comfort. But you never check for the update of your total plugin. You have to know that Database works for every nooks and corner of your website . Plugins are very useful and a must for a WordPress website but it should be regularly updated. Otherwise, Database won’t work with old plugin, and you will see this error message again.
  5. Comment spamming : What is comment spamming? – Comment spamming is an automated system by machines or robotic technique for advertising product of a company. I was a victim of this problem. CSS hack is another comment spamming issue. However, over spamming of comment may bring down your site as the database cannot determine whether it is by users or robot. My hosting provider banned me one day for over comment spamming. I requested them to run again, and they gave me some solutions. I used Akismet plugin to catch spam and was successful in this regard.
  6. CDN and Caching : If your CDN (content delivery network) is not properly set up and if you store caches in your website you may fall a victim to this problem.

 

Solutions of this error message Error Establishing A Database Connection

#1 (Language and database) organized connection between MySQL and PHP : To free this bug go to your WordPress website cPanel by visiting (yourdomain.com/cpanel). Then all you have to do is, go to root folder then download your “wp-config” file. Open it notepad++ or any code editors that you may have.organized connection between MySQL and PHPCheck whether DB Username, Database name, and DB Password are changed. Make sure that the DB username, Database name, DB Password on the wp-config file matches the DB username, Database name, DB Password of the database that you had initially given in your cPanel (Find the phpMyAdmin or MySQL in your cPanel). After doing this upload it back to the server.

#2 Database corruption solution : Open file manager>public_html>wp-configDatabase corruption solutionagain in notepad++ or any code editor and input the following line at the bottom of the script.public_html wp-config

define(‘WP_ALLOW_REPAIR’, true);

define wp-configThen type in the address bar like this www.yourwebsitedomainname.com/wp-admin/maint/repair.php You will get a message option like given below.
Repair Database
Click on repair database or optimization option. It may take a few moments to complete the process. Then delete the code line which you recently added to wp-config. Now you can access to your website even your visitors.
But if you get a message like this one then think your website is okay to use.
Allow Auto Repair Database
You are done.

#3 Proper hosting guide : If you fail to solve this problem continuously change your hosting plan from your hosting provider. I used shared hosting, but it had some bug that is why I changed my hosting plan.
Proper hosting guide#4 Plugin : Update your plugin regularly. Never use any plugin or themes which make you do more functions or avoid using old plugins. You should not use plugin unnecessarily. I use w3totalcaches, Yoast SEO, Akismet, antispam bee, SI captcha, Analytic counter as extra to get a better result.However, these were the possible solutions from my experience on how to fix error in establishing database connections in WordPress. If you face further any critical problem, knock your hosting provider to solve this error message very soon.

About Nikhil S

He is one of the co-founders of TBT. He loves to write about WordPress & SEO tutorials also he is a Computer Science Engineering Graduate.

Leave a Reply

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