How to Fix “Error Establishing a Database Connection” in WordPress

Hostinger Sale
How to Fix “Error Establishing a Database Connection” in WordPress

Sometimes you visit your WordPress site only to see this scary message:

"Error establishing a database connection"

This error is very worrying. It can mean a host of things, and the message itself doesn’t tell you much. The first thing everyone tries is repairing the database. Sometimes that does the trick. Another issue can be that your site is overloaded with visitors – it happened to me once! In which case you need to either reduce the load by cutting out spam, or increase your server capacity.

But what if these don’t work? One possible problem is that your site URL is configured improperly in the wp_options table.

Updating the “siteurl” variable in wp_options Table

This solution sometimes clears up the problem.

Step 1: Access your Database (Either through phpMyAdmin or some other means)

You can usually access your database through cPanel’s phpMyAdmin tool:

Step 2: Select the wp_options table for your Database

Once you access it and provide your credentials, select your database and the “wp_options” table as shown below:

Step 3: Update the “siteurl” option via SQL

Next, access the “SQL” tab at the top and write the following inside it:

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'

Here, replace the section in bold – YOUR_SITE_URL – with the name of your own site. For me, it looks like this:

Once that’s done, click the “Go” button at the bottom right of the screen and this should run your query. This might solve the problem you’re facing. Keep in mind that this is just one possible reason why you’re getting this annoying error. There could be another underlying reason. But this could definitely be tripping you up.

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclosure: We receive a compensation from some of the companies whose products are presented on our website.