Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Discover and Fix WordPress Database Connection Error

Errors are not uncommon in Wordpress development. Since WordPress is an open source platform with a huge number of themes and plugins, errors often pop up during the development process.

Perhaps, the most common error that WordPress developers face is Error Establishing Database Connection. Since databases are an integral part of the WordPress dev process, database connectivity errors often crash the build.

I decided to dig a bit deeper into the causes of this error. This article details the various causes behind the error and how developers could rectify the error to ensure smooth sailing for the project. I have tried to keep things as simple as possible. However, since this article is for WordPress developers, I assume that the readers will have a basic understanding of PHP and MySQL.

Understanding the Error

A WordPress website is built using PHP (that renders the web page) and relies on MySQL for database functionality. Before presenting possible fixes, it is important to understand the causes of the “Error Establishing Database Connection” error.

This error is pretty self explanatory, and just by looking at it, it can be established that the website could not connect to its database. The problem is that there is no single cause of this error. Some common causes are:

  • Incorrect database credentials in wp-config.php. In many cases, this is caused by changes in the database credentials.
  • Corrupted plugins and themes can overflow or crash the database tables.
  • Database is unavailable due to unresponsive server or refused connections because of high traffic.
  • Bad WordPress database connection code.

Resolving The Error

The first step in resolving the error is identifying the cause.

Note: Before making any changes to MySQL and WordPress core files, always take a full backup of your website.

Check with Your Hosting Provider

The first place to look for a cause is the hosting provider that host the website and the database. Confirm that the server(s) hosting the database and website are up and operational. If everything looks good and the provider confirms that everything is in the green, proceed with the next step.

Examine wp-config.php

Fixing wp-config.php is pretty straightforward, and in most cases solves the problem. The file is usually located in the root directory. Open the file in any text editor.

Check if the database credentials (host address, username and password) is correct. In order to cross check the credentials, check phpMyAdmin.

If you see the database in the list, you are good to go. Otherwise, you have to restore it from the backup or create a new database.

Now go back to wp-config.php and add the following snippet at the end of the file

define ( ‘WP_ALLOW_REPAIR’ , true);

This snippet enables WordPress to run database repair without accessing it through phpMyAdmin. Now in the browser, go to www.yourdomain.com/wp-repair.php. This will open a new window where you can select ‘Repair Database’ to initiate the repair process.

Once the process is completed, go ahead and delete the code snippet you added in wp-config.php to avoid any security risk.

Fixing Corrupt WordPress Installation

Over the time, WordPress files can get contaminated with unnecessary code which further causes performance issues. This can be fixed easily but it is important to take a backup before restoring WordPress core files.

Download a fresh copy of WordPress and unzip the folder. Delete wp-config.php and wp-contents folder so that the current wp-config.php file and the theme folder is not affected.

Now upload the remaining files to the existing WordPress website to replace the corrupted files. Now purge the browser cache and reload the website in a new tab.

Run A Scan for Vulnerabilities

The open source nature of WordPress makes it vulnerable to vulnerabilities. Hundreds of WordPress websites become the victims of security breaches and intrusions. It is important to run security scans regularly to ensure the integrity of your WordPress site .

There are several tools that carry out security scans. In this article, I will use WordFence, a renowned WordPress security plugin.

Go to wp-admin and under Plugins, add the WordFence plugin. Activate the plugin and navigate to the Wordfence dashboard

Scroll down and click “START NEW SCAN” to initiate the scan.

Once the scan finishes, it will show the results about the security situation of the website.

Summary

In this article I tried to cover as many solutions as possible and I hope after going through this article you are able to fix the infamous “EEDC” error. Let me know how this article has helped you out.

The post How to Discover and Fix WordPress Database Connection Error appeared first on WPblog.



This post first appeared on WordPress Tutorials And Guides, please read the originial post: here

Share the post

How to Discover and Fix WordPress Database Connection Error

×

Subscribe to Wordpress Tutorials And Guides

Get updates delivered right to your inbox!

Thank you for your subscription

×