How to Fix the Error Establishing Database Connection in WordPress

You face ‘error establishing database connection’ issue in WordPress due to many reasons. Beginners feel more agitated because the error seems to be irreparable. Don’t worry! You can fix this issue by a few ways.

In this post, we’ll help you learn how to fix the error establishing database connection in WordPress.

The reasons why this problem occurs is due to the wrong database information in your website’s settings. Other causes of this issue are an irresponsive database server or corrupt database. Since WordPress needs it to help your visitors see your website information, it’s important that your database remains in a working condition all the time.

Information that WordPress needs to connect to your database:

Database name, username, password, and server/host

The file that has this information stored in it is wp-config.php. In case, any part of this information is wrong, your WordPress will show the message of ‘Error establishing a database connection’.

Here are some useful ways to fix error establishing database connection issue in WordPress.

Fixing the Error Establishing Database Connection in WordPress

  1. Ensure Your WordPress Database Information Is Correct

As told above that database connection gets lost because the required information stored for the connection might be incorrect. So, you can fix the issue by correcting this information in the wp-config.php file through FTP, file manager in your hosting account, or your WordPress admin panel.

Once inside the wp-config.php, search for these sentences:

// ** 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' );

Take a look at the information for your website’s database name, username, password, and server (i.e. host). It should be correct.

If you don’t already know about this information (except for the host/server information for which we have provided information in the next point), get it from MySQL databases in your hosting account dashboard.

After correcting the wrong information in the wp-config.php file, access your website again. The issue should disappear now.

  1. Make Sure The Database Host/Server Info Is Correct

After checking the above information, it’s good to check your database server or host information if the problem still persists. You can get this information by contacting your hosting provider to check whether localhost is your database host. If not, then get that information and check the wp-config.php file to confirm that the information stored there matches the information you have acquired.

  1. Repair Your WordPress Database

If the problem is not with your database error, then it might be something like “One or more database tables are unavailable. The database may need to be repaired”. In this case, you need to fix the database. Here’s how:

  • Access your wp-config.php file
  • Search for the sentence that says, “That’s all, stop editing! Happy blogging” and paste this code before this sentence:
define('WP_ALLOW_REPAIR', true);
  • Now, access your website’s settings page the URL of which looks like this:

[Note: Replace the with your website’s URL.]

Once the repair task is complete, remove the above said code from the wp-config.php file.

  1. Make Sure The Database Server Is Up And Running

In case all these troubleshooting steps fail, you need to check your database server’s responsiveness. Perhaps the real reason lies there. Sometimes, due to heavy traffic a database server gets down. When this happens, your website gets slow. To fix this issue, you can connect with hosting provider and check if the issue is with the server.

If everything is good and your WordPress still faces error establishing database connection, you can do some other solutions as well.

  1. Update Your Website’s URL

You can access the phpMyAdmin to update your WordPress website’s URL. You can get there by accessing your website’s hosting account. Now, go to your WordPress database and navigate the SQL menu. This menu has a MySQL query on the top of it that looks this way:

UPDATE wp_options SET

option_value='YOUR_SITE_URL' WHERE


Give your website’s URL wherever it is asked and replace ‘wp_options’ with your preferred table name.

  1. Restart Your Web Server

If you are on a VPS host, local server, or a dedicated server, you can also restart your server to see if the database connection error is temporary. In this way, you can easily fix the error establishing database connection in WordPress.

Your Comment:

Related Posts



How To

How to Fix Error Too Many Redirects Issue in WordPress

Too many redirects issue on WordPress? No worries! This happens due to an incorrect settings or faulty plugin. When this issue arises, the user is unable to enter their website’s dashboard. Go through this complete post and save yourself from the hassle of not being able to access your website due to the ‘too many redirects’ error. […]



How To

How to Fix Add Media Button Not Working in WordPress

WordPress is becoming advanced day by day but there are some technical failures that keep occurring every now and then. Among those common issues is the add media button not working issue. The worst part that users feel so much frustrated about is that there is no warning or notification why the button isn’t functioning. No matter[…]



How To

How To Fix WordPress Login Page Refreshing/Redirecting Issue

The issue of WordPress login page refreshing/redirecting is very common. When this happens, users get locked out of their website’s admin dashboard and cannot access anything inside it. Although this WordPress issue can occur at anytime due to some specific reasons, there are some easy solutions to resolve it. In this post, we help you discover how[…]