These days creating a website or a blog can be done by anyone with a little know-how and some elbow grease. However, sometimes things go wrong and it’s difficult to figure out why. That’s where the third ingredient comes in: experience. Let me know share from my experience how to fix a very common error. You can imaging leaving this error unattended will cost you a lot of rapport with subscribers, customers and will cost you revenue if you make money either directly or indirectly from your website.
What does it mean?
As the name says, this is a problem connecting to the database. Two different systems come into play when making a database connection. First, is the the MySQL database that stores all the content, admin settings, plugin settings, theme settings, etc. of our website/blog. Second, is the PHP files used by WordPress to store and retrieve information from the MySQL database.
When the database connection fails these two separate parts, the MySQL database and the PHP files, aren’t able to communicate.
What are the possible causes and solutions?
Let’s start with the easier and more common causes first and work our way to the more complex and rare ones. Another thing to remember is that WordPress comes with an in-built repairing feature, which can be activated saving the WP_ALLOW_REPAIR line below to the wp-config.php file. You can do this via the File manager of your hosting account cPanel or via FTP.
#1. Didn’t Connect The User to The Database
Sometimes it’s easy to overlook this step. The wp-config.php file requires a database name, a username and a password. You can create all of those and put them into the config file without connecting the user to the database. That will cause this connection error.
Below where you created the username and password there will be two drop downs. In one drop down you choose the database in another drop down you choose the username. Then you click the button below to link them. On the next page you will chose the user privileges. The following privileges are all that a normal WordPress user would need and setting just these is good for WordPress security: SELECT, INSERT, UPDATE and DELETE plus CREATE and ALTER (for updating WordPress files).
#2. Incorrect Database Login Credentials
Inside the wp-config.php file we have a database name, a username and a password which need to match the login credentials set for your MySQL database. To find the credentials currently being used by your WordPress site, open File Manager via cPanel (or log into your site via FTP). Now select the desired blog or web address from the directory. Inside your website’s root folder select wp-config.php. In the top half of this file you will find the database name, username and password.
That needs to match the credentials of your MySQL database. To find those credentials log into your cPanel and open the MySQL database option. Make sure the credentials match. If they don’t then you need to copy the correct MySQL credentials into the wp-config.php file. If you are having problems with finding the username and password you can create a new one and connect that user to the database. Use the same privileges as in point 1 above. Make sure you delete the old user that you’re no longer using.
DO NOT FORGET to update the new username and password in the wp-config.php file and you should be good to go.
#3. Incorrect Database Host Name
If your battle with the database connection continues, there could be an issue with your database connect. To evaluate this, go to your wp-config file and check the database host name. Most of the time, the host name is kept confidential and is listed as ‘local host’.
The correct host name can be obtained from the hosting company in some instances. Once the correct hostname is entered and all the changes are saved, refresh the page and hopefully that fixes the problem.
#4. Rare in Corrections
In rare cases, one could find problems with ‘stable prefix’ in the wp-config file. No changes should be made to it on your own and you should get it solved by the hosting company to avoid deletion of your blog or website data.
If you’ve tried all of these and you’re still having problems please leave a comment below and we’ll try to help you fix the problem.