[SOLVED]’Error establishing a database connection’ in wordpress

One of my clients got this error in his wordpress:

Error establishing a database connection

It is one of those vague errors which give very little information about what caused it. On going to /wp-admin, it gave error:

One or more database tables are unavailable. The database may need to be repaired.

I added “define(‘WP_ALLOW_REPAIR’, true);” in wp-config.php and clicked on ‘repair’, it showed that all tables have been repaired but I was still getting the error about wordpress not being able to connect with database. It was actually able to connect but there was some other problem. I checked if any table was missing from the database, but it was not.

Finally after 2 hours of searching for a solution, I found it. In wp-options table, just make sure the option_value for the option_name ‘siteurl’ is your site’s url. You can also do this by executing the following sql statement (you can use phpmyadmin):

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

Replace ‘YOUR_SITE_URL’ with your site’s url. For eg; for my blog it would be:

UPDATE wp_options SET option_value='https://www.absolutelytech.com' WHERE option_name='siteurl'

That would make the error go away. Please note that this is just one of the solutions to this problem, it may not be solved after following the above steps. In that case, it might’ve been caused due to different reason and you must search for another solution on wordpress forum.

Cheers!

Leave a Reply

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