Error establishing a database connection is probably the most common MYSQL database error, which bloggers see on their WordPress websites. In the past, I’ve also faced this problem so many times on my WordPress websites. If you are new to WordPress , then this can be really frustrating as there are manycauses for this problem. Usually you will see this error on your website when you install, upgrade, downgrade or migrate WordPress from one server to another server.
In this post, I’m going to explain to you reasons for “Error establishing a database connection” and how you can easily resolve this small, but frustrating WordPress database error in less than two-three minutes.
Main Causes Of “Error Establishing a Database Connection in WordPress” are as follows:
- Wrong MYSQL database login details (Most common cause)
- WordPress database is corrupted
- MYSQL Server is down
- MYSQL Database User Has Limited Privileges
Wrong MYSQL database login details
Most of the time you will see “Error Establishing a Database Connection” due to “wrong MySQL database login details”. You will have to open your wp-config.php file(located on your root folder) through FTP and file manager and check whether database details i.e. (Database name, database user, database password and database host )are correct or not. There should not be any typing mistake. You can find your database details from your web hosting cpanel. Reset password in case you don’t know your database password. It should look like this.
define('DB_NAME', 'Enter your database name here'); define('DB_USER', 'Enter your database username here'); define('DB_PASSWORD', 'Enter your database password here'); define('DB_HOST', 'Enter either localhost or 127.0.0.1 here');
How To Repair Corrupted Database In WordPress
If you are getting ‘Error Establishing a Database Connection” only in back end i.e. on WordPress dashboard(wp-admin) then your WordPress database is corrupted. For repairing database you need to add the function given below on your wp-config.php file.
After you have added above code you need to visit the link given below in snapshot for completing repairing process. Click “Repair” or “Repair and Optimize” and in a few minutes your database will be repaired.
MYSQL Server is Unresponsive
If your database is not corrupted nor you have entered wrong login details in wp-config.php file then you seriously need to contact your web hosting provider whether your MYSQLserver is responsive or not? Most of the time due to high traffic, mysql server becomes unresponsive and as a result you see this error on your website or your website will become slow.
You may also like to read: How to add Google Analytics In WordPress In Less Than 5 minutes
MYSQL Database User Has Limited Privileges
Sometimes MySQL database user privileges can become corrupted or limited. So in order to fix this you will need to delete the current user that is connected to your database. After deleting current user, create new user with full privileges to your WordPress MYSQL Database. Now open your wp-config.php file and replace old database username with new username. That’s it.
Note: Try this method only if none of the methods given above work.
Do let me know via comments if you faced “Error establishing a database connection error” and if the solutions provided in this post solved your problem. If you know any other method by which we can fix this issue then do share it with us.
He is the guy behind WPSeoTricks.com and have been working in the Internet Marketing field for past seven years. He lives in New Delhi,India and loves to educate the masses on WordPress, SEO and Affiliate Marketing. You can hire him for blog consultancy or web development services.