Solving the Error Establishing a Database Connection Problem in WordPress

You have already faced the problem of the error establishing a database connection on others sites or on your own site. It can be frustrated if you are a newbie in WordPress. In this article, I will show you how to fix error establishing a database error in WordPress in detail.

 

First thing first, why are you getting this error?

You are getting this problem because you site is not able to connect to the database properly because of some unknow issues. Maybe, you are facing the problem, you didn’t put the correct login credentials (username, password, database name) or it have been changed by someone. Maybe your database has been corrupted because of some bad plugin or server.

Are you facing the problem for /wp-admin as well?

First, you should check you are getting this problem on front-end or back-end or both sides. If you are getting this error on the /wp-admin/ side, you may have to repair your database if message is something like “Database tables are not available and the database need to be repaired”. If the error is popping up on both sides so maybe you didn’t put the database login credentials correctly.

Repair the database if you are getting repair error

Go to your root directory and open config.php and add the following code

[code type=”codetype”]define(‘WP_ALLOW_REPAIR, true);[/code]

When you have done that, you can go directly via the URL http://www.yoursite.com/wp-admin/maint/repair.php. You will find the screen like this:

repair databas

Click on the “Repair Database” to repair the database. Please don’t forget to backup your database first.

Fixing the wp-config.php file

Check your database login credentials. It could be like this:

[code type=”php”]

/** The name of the database for WordPress */
define(‘DB_NAME’, ‘mydb’);

/** MySQL database username */
define(‘DB_USER’, ‘root’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘abcdef’);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

[/code]

Check your MySql server side

You may have facing the problem because of lot of traffic coming to your site and your server is unable to handle too much load (you may have facing the problem if you are on shared hosting but you can face this problem on dedicated hosting too as I have faced). So, quickly contact to your hosting provider’s representative and ask them that your MySql server is responsive or not.

Duan Lingxin

Duan Lingxin

Content crafter and chief editor at Scratching Info. Also regular contributor on other major online tech platforms. Security Specialist by day and a writer by night, he does his best to instill his knowledge about tech while delivering inspiring and life changing resources through his writing,

More Posts - Website

1 thought on “Solving the Error Establishing a Database Connection Problem in WordPress”

  1. Very helpful resource. Thanks for sharing this valuable information. Am going to give a try to resolve this error.

Leave a Comment