- 1 Fixing The Dreaded ‘Error Establishing a Database Connection’ in WordPress
- 1.1 Main Causes Of “Error Establishing a Database Connection in WordPress” are as follows:
- 1.2 Wrong / Incorrect MYSQL database login details
- 1.3 How To Repair Corrupted Database In WordPress
- 1.4 MYSQL Server is Unresponsive
- 1.5 MYSQL Database User Has Limited Privileges
Fixing The Dreaded ‘Error Establishing a Database Connection’ in WordPress
Error establishing a database connection is probably the most common MYSQL database error, which bloggers see on their WordPress websites. In the past times, I Have also faced this problem so many times on my WordPress websites. If you are new to WordPress CMS , then this can be really frustrating as there are many causes 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.
[myinlink sub=”How to Create Apple ID Without Credit Card in 2 minutes with 7 Simple Steps” link=”http://devsgeek.us/create-apple-id-without-credit-card-2-minutes-7-simple-steps/”]Create Apple ID Without Credit Card[/myinlink]
Actually 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.
Note: Before you make any database changes, make sure you have sufficient backups.
Main Causes Of “Error Establishing a Database Connection in WordPress” are as follows:
- Wrong / Incorrect MYSQL database login details (Most common Problem)
- WordPress database is corrupted
- MYSQL Server is down
- MYSQL Database User Has Limited Privileges
Wrong / Incorrect 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.
All this information should be given to you (if not actually entered on your behalf) by your host. However, if you’re using a more flexible setup (i.e. not a one-click type of install), you should check your username, password, and the name of your database. Your best bet is to copy and paste all the data directly from the medium in which it was given to you.
[myinlink sub=”How to Manage Too Many Chrome Tabs Using Chrome Extension” link=”http://devsgeek.us/manage-many-chrome-tabs-using-chrome-extension/”]Too Many Chrome Tabs Using Chrome Extension[/myinlink]
Note: Passwords can sometimes have dashes or periods at the end that aren’t normally selected.
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.
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
All of the information contained within quotes, for example ‘database_name’, must match exactly with your actual database credentials. Even an extra space after the quotes can cause an error message.
Note: In Database Host field enter either “localhost” or 127.0.0.1.
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.
Option #1 Enable the WordPress Database Repair
Following the step #2 above, you’ll want to open up your wp-config.php file using the editor.
Scroll to the bottom of the file and add the following line of code:
define( 'WP_ALLOW_REPAIR', true );
Save your changes, but keep the editor open, you’re going to need it in a few minutes.
Next, open up a new tab in your browser. Navigate to the following URL:
This will open up the WordPress database tool that will look like the image below. From there, you can select either “Repair Database” or “Repair and Optimize Database”. However, to stay on the side of caution, it might be best to simply repair the database at this point in time.
[myinlink sub=”The Simple Way To Block Windows 10 Upgrade On Windows 7″ link=”http://devsgeek.us/the-simple-way-to-block-windows-10-upgrade-on-windows-7/”]Simple Way To Block Windows 10 Upgrade On Windows 7[/myinlink]
Once this step is complete, go back to your file editor, delete the line that you added at the bottom and save the file again. You have now disabled the repair tool.
Note: Please remove the above function from wp-config.php file when your database is 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.
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.
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.