Fix-Error-Establishing-a-Database-Connection-WordPress

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:
http://www.abc.com/wp-admin/maint/repair.php

[Note: Replace the www.abc.com 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

option_name='siteurl'

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

change menu color in wordpress

09

Jun
How To

How to Change the Menu Color in WordPress?

You have spent so much time searching for the most appropriate website theme as per your business. You have finally found the right one: the best layout, font, and everything else. But you are facing an issue which is how to change the menu color. Changing header color in WordPress is also easy. Do not worry, WordPress […]

Change WordPress Theme

05

Jun
How To

How to Change WordPress Theme without Losing Content?

Do you want to change WordPress theme without losing content? If yes, this guide will help you. WordPress is a CRM that can be quickly modified. Your website may have been outgrown to an existing theme and would obviously look amazing with the added features. Altogether, a WordPress theme will accomplish everything.   All in all, you[…]

Change WordPress Background Color

01

Jun
How To

How to Change WordPress Background Color of a Single Page?

The first thing any website visitor notices is the background color and font of a website. Agree? The background color gives a powerful impression of your business. Well, it’s one of the essentials of quality design. The color and the website visuals reflect your brand, style, readability, and even professionalism. This is the reason why deciding the[…]