How To Fix A Database Error In WordPress And Have A Peaceful Sleep At Night?

WordPress has a really simple user interface, but sometimes it can run into troubles. That is to say, WordPress errors are very common to occur and can throw you for a loop. These errors are sometimes a bit tricky to resolve but do not panic because WordPress errors are fairly common and professionals are constantly on their toes solving and bringing forth new solutions to fix WordPress errors.

One such common error is when WordPress displays an error message saying “Error establishing a database connection.” If you are a beginner, this error will be impossible for you to fix without any guidance, on your own. There can be various reasons behind the error, and you need to find out the cause of it. But do not worry, by following this article you will get to know all about databases, all the possible reasons behind its error and how to act accordingly. All the solutions are presented in simple and easy steps that will be very easy for you to follow.

wordpress 1

What Does A WordPress Installation Store In The Databases?

Every time you install WordPress, it saves this information of the installers in its database:

  1. User Data: Details of the social media platform the user links it to, the passwords, usernames, etc. Whenever a user registers her in your website, that information is added to your database.
  2. Your posts: All the posts that you make on WordPress, the body of the writing, the title, metadata, publishing date and time, all are stored in your database.
  3. 3. Public Comments: All the comments and responses that have been made on your website are saved, along with the information about the time and the person who made it, s saved to your database.
  4. 4. Taxonomy of the website: The way you categorize and demarcate all the pages and posts of your websites are saved to the database.

Whenever in WordPress, you begin to load some page; the platform connects to the database to look for the data that is required to bring it forth. Your website can only and the only function when it can establish a connection with its database.

How to solve the Error Establishing a Database Connection Problem in WordPress?

Follow the solutions presented here, from step to step and you will end your misery, all by yourself and the Database Error will be fixed permanently.

wordpress 2

  1. Use the feature Repair Database of WordPress

There is a feature in WordPress called Repair Database, which will help you in fixing corrupted files. This option is usually kept, by default, turned off. Therefore you have to enable this feature and check if your problem has been fixed.

To enable this, you need a File Transfer Client, for example, FileZilla. This will allow you to connect to the server and let you transfer the files, to and fro. First credentials will be provided to you by the 000webhost, and you will log into the server using them. They are mostly sent to your inbox, right after you sign up. If you do not receive them, then go the Settings, then the General section and the credentials are present at the top right corner of the screen.

Once you get the credentials, you will open the FTP client. Log into the website, and follow the steps mentioned below:

wordpress 3

  • Open the ROOT folder in WordPress.
  • Open the wp-config.php file that you will find inside, and select the View or Edit option.
  • After opening this file with the local text reader, you will find a line “That’s all, stop editing! Happy blogging.”
  • Now paste the code “define (‘WP_ALLOW_REPAIR’, true ); right above the aforementioned line.
  • Save changes and exit.
  • So the disabled feature is now enabled and you will navigate to www.yourwordpresswebsite.com/wp-admin/repair.php and select the Repair Database option. Now WordPress will try to fix the corrupted database and if done successfully, you will re-access the website. This will only work if you have access to your backup, and if this does not work, then there are other ways to troubleshoot this error.

 

  1. Check the Login Credentials of the WordPress Database

There might be some issues with your login credentials, and WordPress cannot connect if it has not got the correct credentials, or maybe it might try connecting to a completely wrong database. You will get that fixed right after you read the following steps.

First, go to your control panel and open the screen named Manage Database. Only one database name will appear under the field DB Name. Note the name of leaving the window opened. Beside it, you will find the username of the admin of the database. You will need both of these values shortly but now open the Manage option and then open the Change Password option and enter a new password.

Note the new password that you enter. Now open the FTP client and complete these steps:

  • Open the ROOT folder in WordPress.
  • Open the wp-config.php file that you will find inside, and select the View or Edit option.
  • In the file, find the line “define (‘DB_NAME,’ ‘yourdatabasenamegoeshere’); so now the placeholder will read as the database instead.

This line will be followed two other lines where the username and the password respectively.

If there a value that does not match with what you had seen earlier, then replace them and add new passwords as well. Save the changes you have made in the file and opened the website. The troubleshooting has been done successfully, and you have worry-free navigation before you. 000webhost.com has prepared a detailed, beginner-friendly guide on WordPress database error.

Restore the WordPress Website from Backup

This is the last resort that you can take, but not an advisable one. If you have backed up all your recent works, then restore the entire website from the backup and your problem will be solved.

If you cannot access your Website at all, then the procedure will not be this simple. Backup tools for the WordPress website work by restoring t from the dashboard of the website. But the website being inaccessible, you have two other ways to go around. One option is you can use the control panel of your web host to create a backup. But all providers may not have this feature; you can make sure by checking it. Log into the control panel and look for an option called backup or something related to it.

If your web host does not offer this feature, you might want to consider using another web host that does.

Another option is there, which is creating a backup manually. To apply this method, you must have backup files stored locally or stored in the cloud and that you can access them at all times.

Install WordPress anew and amend it to your server’s root folder and then remove the older one by:

  • Log into the server.
  • Access the root folder of WordPress. It is usually called public HTML or www or the name of your website.
  • Enter that folder, select every file and all other directories, etc., and erase everything.

What you have done is replaced the corrupted website with a fresh and amended one. All your themes, uploads, plugins will be restored from your manual restoration.

So it is pretty clear that you may sometimes face database errors from WordPress, but you will solve the problem, each time, successfully.

About Author