2 ways to fix the “Error establishing a database connection” in WordPress .
The “error establishing a database connection” is probably one of the most common errors WordPress users can encounter. This error occurs when your site is unable to connect to its database. In this blog, I will show you what this issue “Error establishing a database connection” is and how to solve it.
What Is The “Error Establishing a Database Connection”?
WordPress relies on two major technologies: PHP and MySQL.
1) PHP: PHP is a server-side language, which means that it runs on your web hosting server.
2) MySQL: MySQL is the database management system used by WordPress to store and retrieve your blog information.
So the error “Error Establishing a Database Connection ” occur when your website files are not able to connect to your database.
Common Causes of the Error Establishing a Database Connection
- Incorrect Database login credentials.
- Corrupted WordPress files.
- The database server not responding.
- Problem with hosting provider.
In this blog I will show you how to fix the “Error establishing a database connection” in WordPress.
Method 1: Check Your Database Credentials.
This is the most common cause of the error establishing database connection error. Follow these steps to check the database credentials.
- Database name
- Username
- Password
- Database server
All these are the database credentials. All this information is stored in the wp-config.php file. If any of this information in the file is incorrect, WordPress cannot establish a connection and you’re given the connection error.
STEP 1: Login to cPanel.
STEP 2: Navigate to the Files. Click on File Manager.
STEP 3: Find the public_html and click on that.
STEP 4: Look for the file named wp-config.php and right-click to open the options, and then select Edit.
This will open a set of database information and configurations. Find and take note of the following data:
- DB_NAME – database name
- DB_USER – username
- DB_PASSWORD – password
- DB_HOST – database host
STEP 5: Now go to the MySQL database settings to see the information with the database name, username, database password, and hostname. Next, we will need to verify that this information is correct. Navigate to the MySQL Database in cPanel.
STEP 6: Next, look at your current Database name, Current Users to confirm your database name and username.
If all credentials are entered correctly, the error should be gone when the website loads again. After that, try visiting your website again to see if the database connection error has disappeared.
Method 2: Repair Your WordPress Database
If you can still see the error, then this means that something else is wrong. And If you’re still receiving the error message like ,you can try repairing the database to fix possible corruption. In this case, you can repair the database by adding a line of code to your wp_config.php file.
Follow these steps to add a line of code to wp_config.php file.
STEP 1: Login to cPanel.
STEP 2: Navigate to the Files. Click on File Manager.
STEP 3: Find the public_html and click on that.
STEP 4:Look for the file named wp-config.php and right-click to open the options, and then select Edit.
STEP 5: Open the file and scroll to the section that says ‘That’s all, stop editing! Happy blogging’. Just above this line, add this code. Input the code, and don’t forget to save the changes.
define('WP_ALLOW_REPAIR', true);
STEP 6: Next, go to http://www.your-site-domain.com/wp-admin/maint/repair.php on your browser. I have used http://www.risenepal.com/wp-admin/maint/repair.php.
This gives you two options:
- Repair Database – WordPress will look for the common problems and repair them.
- Repair and Optimize Database – WordPress will repair and look for things it can optimize to improve the performance.
Choose the one that fits you better. Both can take a while to complete. After the repair process is over, check your WordPress site and see whether it’s back to normal.
If so, go to your wp-config.php file and remove the function immediately. This prevents any website abuse as anyone can access the repair page without logging in.
Alternatives That Users Have Found Successful
1)Make Sure Your Domain Is Pointing to Your Host Provider.
2)Update WordPress or Remove Corrupted Plugins and Themes.
3)Reboot Your Server( In case of VPS).
4)Check If Your Plugin or Theme Files Haven’t Been Corrupted.
5)Restore The Default WordPress Files.
Conclusion
Getting the “Error Establishing a Database Connection” error on your WordPress website can be frustrating. The website won’t load, causing a risk of losing traffic and customers. So for that, we have to use quality themes, plugins, and hosting. You can choose a trustworthy service like eHostingServer.com.
I hope this information helps you to solve Error establishing a database connection” in WordPress . If you find any difficulty then you can contact us through a Support Ticket or live chat. We are there for you.