The more WordPress experience you gain, the more likely it is that you’ll come across the ‘error establishing a database connection’.
This is the most common WordPress database error which means that your website is temporarily down, and that there will be no traffic for you as long as it stays that way.
Eventually, this may even lead to losing regular subscribers, not even mentioning the effect on newcomers that could seriously contribute to your revenue.
For every website owner, it is a scary experience not to be able to access the front or back end of his website, especially when not familiar with some basic development and web service concepts that could help avoid losing traffic.
Unfortunately, most web owners have no idea what this error actually means, neither do they know how to fix it and take the site back to normal.
Why does this error appear?
All WordPress content management software is developed with PHP and MySQL, and that’s because all information needed for the website to function is stored in MySQL databases. Once it is there, WordPress developers retrieve the data and work with it using PHP.
In most cases, once you load a page on the website, you can edit it easily and run it after few minutes.
All you would need is the PHP code used to create it, so that you can access the MySQL database and extract the necessary information.
Different PHP queries will be available to access the name of the author, the title of the post, to retrieve the publication, and much more.
Going back to the ‘error establishing a database connection’, what it usually means is that from whatever reason, your PHP code experienced an error connecting to MySQL, and couldn’t in response retrieve any of the needed information.
This is the reason why these errors transform our pages into blank ones, as the website can’t display any of the content or information available in the system.
Does the /wp-admin/ experience the same problem?
The first thing to check is whether the same error appears on the back end (wp-admin) and the front end of the website.
In case you receive the same message on both ends, it means that you can proceed solving it in the way we are about to discuss later in this article.
If the message is different, however, the problem may be a separate database table, which means you may have to do some reparation work.
Reparation is easier than tackling access to the entire database, and usually requires the admin to add a single line in the wp-config.php file. The place where you should add it is right before the ‘That’s all, stop editing! Happy blogging’ line wp-config.php.
The line is as follows:
define('WP_ALLOW_REPAIR', true);
Once done, visit the page and check your settings using the following link:
http://ift.tt/1ab1nSy
Due the nature of the reparation process, the corrupted database won’t require users to enter credentials and to log in, but will prevent them from doing so once it is fully optimized.
Have in mind that the line must be removed from the wp-config.php file once the reparation is completed, so that users can access it again.
Attempt #1: Checking the content of the WP-Config file
WP-Config.php is one of the most important (or the most important) WordPress file your website installation relies on. It is because this file contains all specific administrative details used to connect with the database, which is why you need to change this file each time you change root or users’ passwords.
Even when you’ve change nothing, your website may experience problems, and we recommend you to do a detailed check of the file to confirm that the content is the same.
This is the content of the file:
define('DB_NAME', 'database-name'); define('DB_USER', 'database-username'); define('DB_PASSWORD', 'database-password'); define('DB_HOST', 'localhost');
Keep in mind that DB_Host is set to localhost by default, but this may not always be your case. It needs to be changed as the host changes, despite of the fact that for most of the popular provides it ought to remain unchanged (BlueHost, HostGator, Site 5).
Attempt #2: Checking the Web Host (MySQL Server)
The daunting Error establishing database connection often appears as a result of increased traffic, and happens because the hosting server can no longer handle the immense visitors load (in particular when you’re sharing it).
The first difference you’ll notice is a serious loss of loading speed, right before the error starts displaying. The smartest course of action here is to contact the hosting provider, and try to find out why your MySQL server is no longer responsive.
You can also test the MySQL server yourself, by checking whether other sites operating with it are experiencing the same issue. In case you see the same error for all of them, the problem is definitely an external one.
On the other hand, if the error appears only on your website, try to connect with the phpMyAdmin database manually (using cPanel). In most cases the process will be successful, and the server will require you to verify the database to confirm that you have all needed access permissions. Once inside, add a new file and name it testconnection.php, and then copy-paste this code inside:
<?php $link = mysql_connect('localhost', 'root', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?>
Here, you must remember to switch the username and the password.
In case the connection is successful, this means that you had all the appropriate permissions and that your access attempt was not the reason why such error happened. Once sure of it, proceed by going to the wp-config file to scan for typos and to make sure all content is correct.
Assuming that you’ve done everything right, but the problem of connecting to the database remained, you will at least know it was the server that messed up the things. Sometimes, it will mean that the entire MySQL server is corrupted and completely down, or that your permissions were not sufficient to complete the desired reparation.
Attempt #3: Fixing other WordPress files that may be corrupted
This is probably the best possible scenario, as it will simply require you to restore the corrupted files. The thing you must be attentive with is not to make a catastrophic mistake, as even most experienced users happen to delete their entire sites. Just to be sure, back up all of your data in advance.
The next step will be to go to WordPress.org, and download a new copy from there. Locate the package on your computer, unzip it, and then delete the wp-config.php and wp-content folders from it. This way, the new version won’t affect the wp-config.php file you already have in place, and won’t corrupt any of your plugins, themes, or stored media.
Afterwards, upload all old files in the WP root folder, accessing it through the File Manager or the FTP. This is done to replace problematic and dysfunctional files with fresh ones.
Complete the process, and then reload the site to check if the error is still there. In case it is, clean the browser’s cache and it will most probably disappear. If it doesn’t, this means the problem was not caused by you, and you need to contact the web host for a solution.
Attempt #4: Checking the plugins
Go to phpmyadmin, log in, look for the wp_options table, and delete all data contained in the active_plugins section. You may also be required to edit data in the recently_edited section. This will help you detect the plugin that is causing problems, and give you an idea of how to fix them.
Attempt #5: Connect with your web hosting provider
In case none of the troubleshooting processes we described works for you, and the error remains on your website, try to contact the host for support. They will ask you to provide all details regarding your problem (including the troubleshooting measures you’ve undertaken), and will consequently define and solve the issue.
Conclusion
This error may be really common, but it is definitely not the scariest one that could appear on your WordPress website. As we discussed in this article, corrupted database connections are easy to solve, and even when you are not ready to do that yourself, there is the web host ready to assist you.
Source: http://ift.tt/2jXttc4
No comments:
Post a Comment