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.
Fix WordPress Database Connection Error
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.
1. 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.
2. 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.
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 of the security situation of the website.
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.
Frequently Asked Questions
Q1. What is database connection error?
A database connection error causes your website to temporarily be inaccessible to visitors. Your website loses its connection to its database as a results it fails to receive files making it inaccessible. This will cause a reduction is traffic and search engine ranking.
Q2. What does this mean Error establishing a database connection?
This error reflects that your username and password information in your wp-config.php is incorrect. This also means that your website and the database cannot be connect. Another meaning of this error could be that your database server is temporarily down.
Q3. Where do I find the WP Config PHP file?
The wp-config.php file is usually located in the root folder of your website with other folders like /wp-content/. Simply right click on the file and then select download from the menu. Your FTP client will now download wp-config.php file to your computer.
Subscribe to Get The A FREE WordPress Ebook Right in Your Inbox
WPblog provides the complete guide to launch your WordPress website completely FREE!
Moeez is ‘The’ blogger in charge of WPblog. He loves to interact and learn about WordPress with people in the WordPress community. Outside his work life, Moeez spends time hanging out with his friends, playing Xbox and watching football on the weekends. You can get in touch with him at moeez[at]wpblog.com.