0


Here, I list different methods for fixing the error, Error establishing a Database connection”. You will get all the solutions at one place.

Method 1: Does the Error occur for wp-admin?

If you are getting the error message when you are accessing wp-admin, then it is signs of database corruption.
So, you have to repair your WordPress database.

For this, you have to access your wp-config.php file. The file has your WordPress installation settings and configuration.

The wp-config file is located in your root WordPress file directory. You need to log into the cPanel, select File Manager, and then access the folder where you installed WordPress.

Wordpress Database

Once the wp-config file is open, you need to add this line of code to the bottom:
define( ‘WP_ALLOW_REPAIR’, true );

The line will enable you to repair your database by navigating to www.yourwebsite.com/wp-admin/maint/repair.php (you have to replace “yourwebsite.com” with your site URL.
You will get two options.

1. Repair Database

2. Repair and Optimize Database

You can choose any one of them. However, optimizing takes more time than just repair.

Wordpress Database Repair

Once you have done the repair, don’t forget to remove the line of code that you added to wp-config. It will not allow anyone to access your database.

Don’t close the wp-config file unless the error is resolved and the website is working again.
If the error is still not resolved, continue to the next step to troubleshoot the problem.

Method 2: Check the WP-Config file

In this step, you have to look at the database settings in your wp-config file. So, go ahead and open the wp-config.php file for editing.

At the top of the file, you would find the credentials for your database.
It looks something like this:

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define( ‘DB_NAME’, ‘database_name_here’ );

/** MySQL database username */
define( ‘DB_USER’, ‘username_here’ );
/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password_here’ );
/** MySQL hostname */
define( ‘DB_HOST’, ‘localhost’ );

So, the WordPress needs these pieces of information to access your database.
They are:

• The name of the database (“DB_NAME”)
• The login username (“DB_USER”)
• The login password (“DB_PASSWORD”)
• The database host (“DB_HOST”)

The WordPress will not be able to connect to the database in case any of these values is not correct.
You should use PHPMyAdmin for accessing and editing the database. It can be located in the cPanel dashboard.

PHPMyAdmin will display a list of databases on your server. Click on the one that matches the name in your wp-config file. It will show tables in the database. Locate the table named, “wp_options” and click on the browse button next to it. You should see your website name, URL, and other general settings here.

If the database name is not correct, fix it in wp-config.

After this, you have to check the username and password.

This can be done by creating a simple .php file to test whether you can connect to the database with the credentials in your wp-config file.

Or

Create a new user and password and update the wp-config file with the new info.

Once you have corrected your database name, username, and password, you just have to correct DB_HOST. In most cases, this value is “localhost.”

Method 3: Fix Corrupted Files

If troubleshooting the database doesn’t resolve the error, then you should try to fix any corrupted files in WordPress. But, before we go ahead, you should backup all your data either manually or by using a plugin. We need new and fresh WordPress files so that the problem can be resolved.

For this, you need to download a fresh copy of WordPress CMS.

Then delete the whole wp-contents folder and the wp-config file. Finally, paste the remaining files into the WordPress root folder. You can use an FTP client. It will replace the corrupted files that are causing the error.

If the error persists, you should contact your web hosting service provider as it is possible that the error occurs at the server end. You should tell them about the measures you took to resolve the problem.


Fixing HTTP 500 Internal Error

The 500 Internal Server Error is a very general HTTP status code that means something has gone wrong on the web site’s server but the server could not be more specific on what the exact problem is.

Post a Comment

 
Top