Ways you can fix the ‘Error establishing a database’ problem In WordPress

Here's how, if you follow the right instructions, you can deal with a common WordPress problem and get back to working on your content.

WordPress is an extremely well structured and user-friendly website. However, at times, there are certain problems which can barely be tackled. The ‘error establishing a database connection’ is one such error, which is difficult to fix. The main reason why it is difficult to troubleshoot is that there might be various reasons leading to this problem.

Though this problem can be at times tricky to tackle, if you follow the right instructions, you will be able to deal with this problem in no time and get right back on working on your content.

Before we try to understand the causes of such an error, we should first understand what exactly a database is. Databases are collections of tables that are filled with information regarding the contents. If you are running a website that has an interactive content, then a database is in use while storing these data. Databases are background elements, which is the reason why no user interacts with the system, and is therefore hardly aware of it. When using WordPress, a database is of primary importance if you desire to run your website at all. The database necessarily stores all your user data, all your posts, the comments on your website and also your website’s taxonomy.

Causes of the ‘Error in establishing a database connection’ in WordPress

When WordPress is unable to connect to your database, your website virtually comes to a standstill. The website, will in fact, not load at all. This will make it impossible for you to either download your dashboard or even your pages. This error, when it takes place, is quite a strange ordeal.

Error establishing database connection screenshot

Here are some of the causes attributed to, when you face this error:

• Your server is down: In some circumstances, it may so happen, that your website is not being able to connect to your database simply because there’s some problem related to the server that is currently in use. It might be that there is simply too much of traffic, or in other cases, this may be related to some permission related issues. If this happens, the fix is a rather simple one.
• A corrupted database: Here the word “corrupted” is used to describe a file that may suddenly stop working. For example, if you are trying to open a text file, and when it opens, it is instead, full of weird symbols instead of what it has. This can similarly also happen to a database, in this case, it becomes impossible for WordPress to understand the codes involved and hence decode the information. The causal factors of such corruption might be a byproduct of some other error or while making changes to it.
• Using the incorrect login credentials: In general, databases store some sensitive and private information, and for this reason, to gain access to this, you need to put forward the correct credentials. WordPress needs full access to the database to keep the system working. If someone changes your password or even alters your user, it will be impossible for you to connect to your database anymore. If you have any other queries, then 000webhost blog post is there for you.

Two ways to troubleshoot the error

1. Use WordPress’ ‘Repair Database’ Aspect: If you have a corrupted database, this is the best way to troubleshoot. This feature is inbuilt in your WordPress account but is switched off by default. This feature needs to be enabled before using to see if the problem can be fixed. To do this, however, a File Transfer Protocol (FTP) clientele is required like Filezilla. For this, you can log into the server using the credentials as given out by your host which are entered into four fields: Host, Password, Username, and Port. Alternatively, you may also log in your 000webhostpanel; there go Settings then a general section where you will find the credentials. Once in possession of these, open the FTP client then follow these steps:

• Go to WordPress root folder.
• Find wp-config.php file, right-click on it, choose View/ Edit option. The file will open using a local text editor.
• In the file look for ‘That’s all, stop editing! Happy blogging’ line
• Paste the code above: define ( ‘WP_ALLOW_REPAIR’, true )
• Save the changes to the file and close it.

After this, click on the Repair Database. After this WordPress tries to fix corruption, if it is successful in doing so, your website will be back on track again.

2. Check and then update the WordPress Databases’ Credentials Login: If the previous method fails, then it can be deduced that the problem is in your permit. WordPress will not connect to the relevant database with a wrong username, password. To troubleshoot, first, open the 000webhost.com control panels, from there, go to Manage Database screen. There must be only one database existing to you, and the name of the database should come under a DB NAME column. Please make sure to take note of this name carefully. Next it will be Field with the database’ admin username in the column DB USER. Remember these, and click on ‘Manage’ button and look for ‘Change Password’ option, and Change the password of your database. Now, open the FTP steps and do the following:

• Go to WordPress root folder
• Look for wp-config.php file
• Right-click and choose View/ Edit option.

wp-config.php

Once it open, then go to the following line: define (‘DB_NAME,’ ‘yourdatabasenamegoeshere’); make sure that your placeholder reads as the database. There should be two other lines following those mentioned above one; the lines should define database username and password correspondingly. If whichever of the following is displayed on your placeholder doesn’t match the one that you had seen on the control panel earlier, make the necessary changes and replace it with a new password. Save these changes to the wp-config.php, then close and access the site. Your website is working fine now.

Ben Lobel

Ben Lobel

Ben Lobel was the editor of SmallBusiness.co.uk from 2010 to 2018. He specialises in writing for start-up and scale-up companies in the areas of finance, marketing and HR.

Related Topics

Website

Leave a comment