Are you facing…?
Error establishing a database connection
You might get curves on your head if you’re a beginner.
But, there’s no need to panic. It’s one of the common problems of WordPress Website which routinely erupts on Godaddy and can be fixed in under 10 minutes.
The problem defines itself that no connection can be made to get data to display on your browser.
Table of Contents
What is actually an error establishing a database connection?
As you know, an interference in connection erupts the frequent error.
Anatomy of WordPress are made of two major parts-
1.WP Files – here images, plugins, theme, wp-config.php etc can be found.
2.Database – It stores post, plugin, theme & WordPress settings, admin & user credentials,
WordPress makes a connection between both by saving database credentials to wp-config.php file located in the root directory of WP files.
Database credential look like this-
define('DB_NAME', 'your_db'); /* this is the name of your WordPress database */ define('DB_USER', 'your_username'); define('DB_PASSWORD', 'your_pass'); define('DB_HOST', 'localhost'); /* this is the web address of your database server */
If we see the issue, now we can easily understand that there is no contact between WP file and database. In order to run the website, we need to establish a connection.
What are responsible for?
Database Server Down – For some reason database server gets stuck. WP core can’t connect and retrieve data. In the scenario, the issue would be reported only if the database server is installed on a different machine than the WP file server.
Massive Traffic – Sudden sprawling spikes in traffic need huge acceleration of the database server. Due to capacity limitation, the server can’t persist and transfer any data.
Wrong Credential – WordPress needs the correct credentials to transfer data properly. But if the keys are not right. Both parts of WordPress are unauthorized to each other, they can’t do a handshake even if both are on the same server.
Corrupted WP File – Defaulting in any tiny plugin and theme update can cause major impact. It can corrupt WP files. Then we can’t get the post images, plugin and theme’s file like stylesheet, function.php etc.
Corrupted Database – Plugin and theme update issues can also impact databases, because their settings are saved in the database. So during troubleshooting the error needs to be looked at.
How To Fix Error Establishing A Database Connection in Godaddy
Now we are going on solutions which will fix the error quickly. I have also included a permanent solution that will keep you away from the error in the longer run.
Now let’s start troubleshooting…
1.Connect Support Team
If you haven’t done anything on your end, it is most probably that the fault can be on your web host’s end.
Although connecting the support team is a good and time saving idea. In the scenario, you have to connect them and ask them,
What is causing the issue?
Mainly you can ask to find out the probable reason?
Did the server get abundant traffic including bot traffic recently?
Is the server down or not responding?
Have their technical team done any server stack update?
Was there some attacks like SQL injection, XSS etc?
If the support team fixes the error, congrats.
If not, they will let you know about database server status, server updates, suspicious activities and traffic soaring. It will make it clearer what you have to do.
2.Wrong Database Credentials
As you know, WordPress establishes a connection between wp files and databases. It requires the correct username and password. WordPress automatically setup it while installing a new WordPress blog. Doesn’t require any action from you.
Normally the credentials don’t change on their own. But if your website experiences some weird cases like changes in the hosting environment and wp files or recent server migration, it may change the database credentials and the website starts encountering the riddle.
To fixing it, go through following steps
1.Go to root folder>wp-config.php file through file manager
2.Open it, find the details and copy it in the notepad.
define('DB_NAME', 'your_db'); /* this is the name of your WordPress database */ define('DB_USER', 'your_username'); define('DB_PASSWORD', 'your_pass'); define('DB_HOST', 'localhost'); /* this is the web address of your database server */
3.Now go to database tab under cPanel
4.Match DB Name and DB User, DB Host – localhost is the default on many hosts.
5.If the details are correct, DB Password might be wrong.
6.Click the change password, copy it, paste in wp-config.php carefully and save it.
The error should be fixed, if not, there is another reason.
3.Database Server Down or Not Responding
The Internet is very fragile. A simple pressure or glitches can burst big. And if your servers are on cheap infrastructure. Believe me, few uncertain spikes in traffic can derail a database.
You can request the support team to restart the database server or if you have root access, you can restart by following Linux command.
sudo service mysql start (paste this in console and hit enter).
But this is only a temporary fix, for a permanent solution you should upgrade your plan or move to robust and modern WordPress specialized web hosting like Cloudways.
Generally on shared hosting, users get crimp server resources that can’t handle even on little traffic soaring. It’s the worst for the interest business.
But now World has got the perfect solution that is Cloud Hosting. It has a robust feature called cluster which is specialized in maintaining zero down time. It transfers the load of traffic to the next available server, if the current server is facing sprawling traffic. The cycle goes on until traffic gets normal.
And you can also enjoy Google and AWS powered VPS environments with just $11/month. Try out Cloudways trial with free $100 extra.
4.Corrupted Database
Faults in disk subsystem[1]My MySQL Database is Corrupted…, controllers, communication channels, drivers, firmware or hardware corrupt database. This is a gruesome issue, valuable data can be lost.
So we always advise, take backups to another server routinely and facing in regular intervals expose outdated server software and weak server infrastructure. Move to robust and modern hosting technology like cloud hosting.
Method – 1
1.Login to your cPanel
2.Browse file manager
3.Go to root folder (public_html)>wp-config.php
4.Add the following the code line just before “That’s all, stop editing! Happy publishing”
define(‘WP_Allow_Repair’, true);
5.visit yourdomain.com/wp-admin/maint/repair.php
6.You’ll see like this, click on any button.
Now WordPress will proceed to repair the database itself. On accomplishment of the automatic process, load your homepage and check if the error is still there.
If no error, tremendous job!. But don’t forget to remove the added code line to revert “wp-config.php” to its previous state.
Method-2
First method can be done in another style, more short, but risky.
If you’re familiar with phpmyadmin a bit and can be cautious, you can step up.
1.in cPanel, click on phpMyAdmin
2.click the database of your website, find it on the left side.
3.Scroll down to the footer, click check all, select Repair table under table maintenance and wait until repair is done.
Check your site, if error is fixed, great or move to the next step.
5.Corrupted Plugin
A subtle bug can cause huge problems. It can create plugins conflict and pugin & theme conflict. The conflicts impact Wordpress working and on a severe level, databases also can’t spare.
The bug comes generally while updating plugins. Here taking backup before installing any update will save your back.
After rolling out an auto update feature for plugins by WordPress has flooded the errors.
Let’s fix it, if it crumble
1.In cPanel, access file manager
2.Go to public_html (If multiple websites are hosted, go to the root folder of the issue facing domain.)
3.Move into wp-content and rename the “plugins” folder to “plugins.old”. All plugins will be automatically deactivated while WordPress can’t find the “plugins” folder.
4.Now reload your web property, if the problem disappears, it means that one of your plugins is the culprit.
5.Go back to file manager and revert the name of the plugins folder to the previous one. We need to find out only the rogue plugin.
6.Now rename your first plugin to plugin_name.old.
7.Reload your site, check if the error still appears.
8.If yes, the error is in another plugin. Now revert your first plugin name to the previous name.
9.Now run the error finding cycle with other plugins till you get a faulty one.
Well done, if you find the buggy plugin, change it with its alternative one or check its official documentation for patching up.
But if the browser screen is blank, there may be a high probability of your corrupted WP core file.
6.Corrupted WP Core
Hacking, uploading malicious files or accidentally changing core files can corrupt WP core files.
Even a buggy plugin can do that. In the scenario, need to restore wp core files with new wp core files.
1.Download fresh WordPress from wordpress.org
2.Extract it, delete wp content folder and convert in a ZIP file.
3.Login to cPanel, go to file manager and download wp-content folder, wp-config.php and .htaccess as safe play.
4.Delete all wp core file (What files have to delete, see in fresh wordpress folder) except wp-content folder, wp-config.php and .htaccess
5.Now upload the zip file to root_folder and extract them.
Now reload the site and check your website.
7.Restore Backups
If nothing worked, the best way to recover from the obstacle is to restore your website from the most recent backup. Backups can be found on your host account, if they keep routinely.
Two Final Steps to Avoid This Error as Much as Possible
Permanently abolishing the issue is not possible, but we can avoid it as much as possible by simply taking two steps –
1.Powerfull and Auto Healing Cloud Hosting – Along with cluster features, cloud hosting has amazing auto-healing capability that makes it 100x better than shared hosting. The feature tackles server and WordPress failures automatically and ensures the server runs smoothly.
Forbes featured Cloudways is powered by World’s top three cloud infrastructures-
- Google Cloud
- AWS
- Digital Ocean
You have full freedom to choose the best of the bests and feel the calm cloud experience.
2.Backups – Install Updraftplus, connect Dropbox and take backup regularly. But if you’re on traditional shared hosting, you may face the error many times. Then installing new WordPress and taking backups will be a highly time consuming task.
So it’s better that web hosting does it for you, Cloudways take backup server level backup, you can also make your backup schedule and in a click, you can restore your blog. So simple.
Wrap Up
In the post, we have mentioned 7 best ways to fix the issue and we hope you would have solved it. But a rich infrastructure and power software enabled hosting can keep you away from the headache. You can focus on improving productivity and business profit.
How was your experience, while eliminating the error or you might have found new way to sort out, plz share it in the comment box.
More Solutions:
- Best 7 Ways to Fix GoDaddy 503 Service Unavailable Easy
- 27 Ways To Fix GoDaddy Slow WordPress Site [Load in 1s]
Meet Ravi Kumar, our web hosting and WordPress speed optimization guru with over 4 years of experience. He’s optimized 150+ websites, uncovering common VPS performance issues. Armed with insights, Ravi ensures smooth VPS experiences for all.
References