How to Fix Error Establishing a Database Connection in WordPress

Error Establishing a Database Connection How to Fix It

It is a common issue and one that is actually part of running modern WordPress built website to have Errors for connecting to your database. WordPress is a dynamic content management system that resides in a Database (usually MySQL) and there are many different ways you can troubleshoot Errors when establishing a Database Connection for websites built on WordPress.

First Step for Fixing Database Connection Issue

Realize that more often than not, this error has nothing to do with your WordPress site but rather the web hosting service you are using may be down temporarily (e.g. server reboot, maintenance or upgrade). That means first thing we should do is double check if the MySQL server is up and operating normally and that you can login to phpMyAdmin

Web Hosting Network Status
Shows modern web hosting user interface for checking Network Status details of a web server where WordPress is installed

And also make sure that you can access phpMyAdmin to double check if you can login to your Database through your web hosting account.

Second Option for Fixing Database Connection Errors

Simply browse in to your MySQL Database options to see if your Database WordPress is built upon is visible, and also check the user for that Database exists. At this stage you should see both the Database Name and the User of that Database. If you can’t, then you need to restore your WordPress site. However, if all is good at this stage, proceed to next step.

MySQL Databases user interface check database option
Shows MySQL Databases user interface check database option

Checking your Database is also an option provided by most modern web hosting service providers such as (Siteground, Hostgator, Crazy Domains, inMotion Hosting, goDaddy) simply locate this option through your cPanel > MySQL Databases

If you are not able to login and MySQL server using phpMyAdmin and get  Error: 2002 (CR_CONNECTION_ERROR) error message means:

 Can’t connect to local MySQL server through socket ‘%s’ (%d) (learn more about Client Error Codes and Messages

What if you don’t know the name of Database your WordPress site is built upon? Or that everything else seems to be okay? Then, browse in to Web Hosting Account > File Manager > public_html > wp-config.php (Right Click and Download a backup) and triple check the details in the default WordPress configuration file (as shown in the image below)

WordPress WP-Config PHP File
Shows default WordPress configuration file named wp-config.php and options for defining Database, Database User and Database Password

How to Fix Error Establishing a Database Connection in WordPress Video Lesson


Once again, database connection errors are actually normal for short period of time, if you’ve followed all the troubleshooting procedures and you still see Error Establishing a Database Connection Message in your internet browser. Then, contact your web hosting provider as they will be able to assist you further.

Author: RankYa

RankYa: Online Entrepreneur, Qualified Web Developer, Google AdWords and Google Analytics Certified Professional. Specialist in: SEO, Website Optimization, WordPress, Structured Data, JSON-LD, Microdata, Microformats, RDF, Schema.org Vocabulary, HTML5, Advanced Image Optimization, Google Search Console, Google Webmaster Guidelines, Social Media Marketing, Facebook marketing and YouTube video ranking.

Thank you for sharing this blog post. Description: 'How to Fix Error Establishing a Database Connection in WordPress is detailed, find all possible ways for fixing WordPress Database Connection errors'