How to fix the connection error with the WordPress database? Find out in this article.
If you’ve been surfing the web for long enough, you must have seen this error a few times. ” Error establishing a connection to the database “; is quite a frustrating error especially for novice users.
Note: Before making any changes to the database, make sure you have necessary backups .
What is the cause of this error?
Well, in short you are getting this error because WordPress is unable to establish connection with the database. Now the reason WordPress is unable to establish a connection with the database can vary.
Your database connection details may be incorrect or may have been changed. It could also be that your database server is not responding, or it could be that your database has been corrupted.
In our research, we have found that the majority of times this error occurs due to a server error, but there could be other factors.
Let’s take a look at ways to fix this problem.
Does the problem occur thus for / wp-admin /?
The first thing to do is to make sure that the same error occurs both on the public interface or “front-end” of the website, and on the dashboard or “back-end” ( wp- admin ). If the error message “Error establishing a connection to the database” is the same on both pages, then continue to the next step.
If you get a different error on the wp-admin , for example something like “One or more sections of the database are unavailable. The database may need to be repaired ” then you need to repair your database.
You can do this by adding the following line to your wp-config.php file . Add just before the line “ That’s all, stop editing! Happy blogging ” .
Once you have done that you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php
Remember, the user does not need to be logged in to access this feature when it is set. Indeed, its main objective is to repair a corrupted database; moreover, users often cannot connect when the database is corrupted.
So once you are done repairing and optimizing your database , make sure to delete it from your wp-config.php file .
If this repair does not resolve the issue, or you are having difficulty completing the repair, then continue reading this article; you might find another more effective solution.
Checking the wp-config.php file
wp-config.php is probably the most important file in the WordPress installation. This is where you specify WordPress details in order to connect to the database. If you have changed your root password, or the database user password, then you will need to change them in this file as well.
The first thing you should always check is if nothing has changed in your wp-config.php file .
Remember that the value of DB_HOST might not always be localhost . Depending on the host, it will be different. For popular hosts like HostGator , BlueHost , Site5 , this is localhost .
Navigate in your directory with these FTP clients to make file transfers to your hosting
Some people suggested to fix the problem by replacing localhost with the IP address. It is common to see this kind of problem when WordPress is running on a local server. For example on MAMP , the DB_HOST value when changed to the IP address seems to work.
The IP address will vary depending on the web host services.
If everything in the wp-config.php file is correct (be sure to check for typos ) then it’s fair to say that the problem is at the server level.
Consult your web host ( MySQL server )
Sometimes the error establishing a connection with the database occurs when your website is overloaded with an amount of traffic. Basically your server just can’t handle the load ( especially if you are on shared hosting ).
Dedicated Server, VPS, Shared or Cloud? What is the best WordPress web hosting solution
This will cause your website to become very slow, and for some users, this error will occur. So the best thing to do is to contact your web hosting provider by phone or livechat, and ask if your MySQL server is in Response mode.
For users who want to check if the MySQL server is running, there are a few things you can do. Try other websites hosted on the same server to see if they have the same problem. If the same error occurs, then it is clear that there is a problem with the MySQL server of your web host.
How do I allow users to edit certain pages? Find out in this article
If you don’t know of another website hosted on this same server, just go to your control panel and try to access phpMyAdmin in order to connect to the database. If you can login, then check if your database user account has sufficient permissions.
Create a new file called testconnection.php and paste the following code inside:
Make sure to replace the username and password. If the connection is successful, it means your user has sufficient permission, and something is wrong. Go back to your wp-config file to make sure everything is correct (re- scan for typos ).
If you can’t connect to the database by going to phpMyAdmin then you know the problem is with the server. It doesn’t necessarily mean that your MySQL server is down. It could just mean that your user does not have sufficient permissions.
It is therefore important to contact your web host in this case, so that they can correct it.
Also discover some premium WordPress plugins
You can use other WordPress plugins to give a modern look and to optimize the grip of your blog or website.
1. Contact form 7 Aweber Add-on
This premium WordPress plugin combines the simplicity of the WordPress Contact Form 7 plugin and add a contact form creation system to your website. It integrates AWEBER’s automatic response module and can send emails directly to your AWEBER list .
Its main features are: AWEBER statistics in your WordPress dashboard, 8 attractive and cute templates to create your own subscription form, and this in a short time, verification of the entire dissemination campaign of your Aweber account in one click, ease of installation, compatibility with the latest versions of jQuery and WordPress, comprehensive documentation and 24/7 support.
2. Total Recipe Generator
Total Recipe Generator is a premium recipe plugin available on WordPress. It gives you the opportunity to present your recipes to users in a way that will definitely help you stand out from the crowd.
This WordPress plugin will allow you to easily transform your website into a website dedicated to cooking recipes . Among other things, you will be able to:
filter the recipes listed according to the amount of nutritional elements (sodium, carbohydrates, proteins, etc.), filter the recipes listed according to preparation time, hierarchical and semantic order, cooking time, difficulty, the type of recipes and all using the drop-down values etc …
3.AccessPress Social Icons Pro
AccessPress Social Icons Pro allows you to create various social icons and link your social profiles from your WordPress website. It is very attractive because you can make, customize and design beautiful icons for your social media profiles.
This premium WordPress plugin offers you 16 beautiful sets of icons that you can choose from. In addition to that, it gives you the ability to create your own set of icons, customize them, set sizes, add multiple effects, etc.
for website maintenance service contact us.