Error Establishing

Database Connection

Here’s what it means, and how to fix it!

error establishing a database connection

Common Causes of Error Establishing Database Connection

🧠 Incorrect Credentials  | ⚙️ Config File |  🔌 Database Server is Down 

💥 Corrupted Database |🔒 Overloaded Server   | 🧱 Firewall or Security Plugin

 

🧠 Incorrect Credentials

⚙️ Config File

🔌 Database Server is Down

💥 Corrupted Database

🔒 Overloaded Server

🧱 Firewall or Security Plugin

How to Fix It (If You’re Doing It Yourself):

First, don’t panic. This error can look pretty intimidating, but in most cases your information isn’t lost, it’s just a connection issue between your website and the database. The good news? Usually this is something that can be fixed pretty quickly.

Follow the steps below to get your database reconnected and your website running smoothly.

The WordPress Database Explained

You will need to understand how your WordPress Database works in order to try and resolve the issue. Your website is made up of two main parts, the files and the database.

Wordpress error establishing database connection

The files are what run the website, this includes all of the code, plugins, theme files and even your images. Think of this as the engine of your website. Engines take many parts to run correctly, and so does your website.

The database (usually referred to as MySQL) is where all of your content is stored. It’s sort of like a digital filing cabinet that holds everything from your pages and posts to your user account information, plugin settings, form entries and even more.

Why am I Getting This Error?

Whenever someone visits your site, WordPress will pull the information it needs from your database to show that information on the screen. If it cannot connect to that database for any reason to get that data, you will see the “Error establishing a database connection” message.

Where is This Error Happening?

Before we discuss how to fix this, let’s first check and see exactly where the error is occurring. This will help us understand where to troubleshoot it.

First, check your website’s homepage, which is normally referred to as the “front end” of your website. This is where the user interacts with your website, and it is also the public view of your site. (Ex: yourdomain.com).

Next, you should also try logging into the WordPress dashboard, which is referred to as the “back end” of your website. This is where developers or administrators update plugins and themes, add code, or change other settings.

If the error is not showing on the backend in the WordPress dashboard, then you might only need to repair your database. In Step 1, we will walk you through the steps to repair your database.

If the error is the same on both the front end and the backend, then skip Step 1 and move on to Step 2.

Step 1: Find Your wp-config File

You can find your wp-config file by accessing your website’s files through your hosting dashboard. You can usually do this by logging in and opening the File manager, or by using an application called an FTP client, like FileZilla. This will enable you to connect to your site’s files directly.

An FTP client is a tool you can install on your computer to connect to your website and manage its files. One of the most popular free options is FileZilla.

Once you’re in your website’s files—through File Manager or FTP—look for a file called wp-config.php. It’s usually in the main folder (called the “root” directory) alongside folders like wp-admin and wp-content. If you see those, you’re in the right place—scroll down until you see wp-config.php.

Once you have located the wp-config file, make a back up first, just in case something goes wrong. You can copy it on the server or download a copy on your computer.

Check Your Credentials

To view or edit the file:

  • If you’re using File Manager in your hosting dashboard, it likely has a built-in editor.
  • If you’re using an FTP client, download the file to your computer and open it with a text editor like Notepad++.

Once you have opened the config file, look for a section that should list your database name, username, and password. You should see something like this:

define(‘DB_NAME’, ‘your-database-name’);
define(‘DB_USER’, ‘your-database-username’);
define(‘DB_PASSWORD’, ‘your-database-password’);
define(‘DB_HOST’, ‘localhost’); 

wpCredentials

You should review these values to ensure there are no typos or punctuation errors in your username, database, password, or hosting information. If you have one extra character, even a space, this could cause an error. If you do make changes, make sure to save the file and update it.

Try Repair with wp-config

Now that you have your wp-config.php file open, scroll down to the very bottom. Look for this line:

/* That’s all, stop editing! Happy blogging. */ or # That’s It. Pencils down

On a new line just above that, add this line of code:

define('WP_ALLOW_REPAIR', true);

Make sure that you type this exactly as shown, using the straight single quotes and not double quotes. One wrong punctuation mark or parenthesis in the wrong place can cause this to fail.

Next, make sure to save the file!

If you are working through an FTP program or file manager, upload the file back to your website. Make sure that you use it to replace the older version, but also ensure that you already have a backup saved before completing this step.

Now, open a new browser tab or window and type this link into the address bar, but replace the “yoursite.com” with the name of your website:

http://www.yoursite.com/wp-admin/maint/repair.php

You should see a page with options to repair the database. Click the button that says “Repair and Optimize Database.” Once the repair has been completed, check again to see if your issue has been resolved.

Important: After the repair, go back into your wp-config.php file and remove the line you added (define(‘WP_ALLOW_REPAIR’, true);). Save and upload the file again to keep your site secure.

Still not working? No problem, let’s troubshoot further in Step 2.

Step 2: Check the Database Server

If you are still seeing this error message, the problem could be that WordPress can’t reach the database server at all. This could be happening if:

  • You are running WordPress on a local server, like your own computer
  • Your hosting provider uses a different database hostname than the default (localhost)
  • The server is temporarily down on the host’s end

Check the Database Hostname

First, check with your hosting provider to see if the hostname is something other than ‘localhost’.

If they give you something like 127.0.0.1, mysql.yourhost.com, or a different IP, you will want to replace ‘localhost’ in your wp-config file with whatever information they give you. Next, save the file and upload it back to your site using your file manager, replacing the old one.

Give Your Server a Reboot

Sometimes, especially during huge traffic spikes, the server could crash temporarily.

It will normally come back on its own within a few minutes, but if the problem continues, reach out to your hosting provider and ask them if the server is down or if it needs to be restarted. They can confirm if it’s a server issue and help you get things running again.

If everything looks correct in your file and you have confirmed the server is working, but you are still having the same error, move on to Step 3 for more troubleshooting.

Step 3: Checking For a Corrupted Database

You’ve checked your database credentials and your server is online, but you are still getting the same error. If this is the case, it is possible that your database may be corrupted. This could happen due to a plugin or theme, your site crashing during an update, or even a hosting issue. Even if you have already tried the repair tool in Step 1, it is possible that the repair did not fully fix deeper issues in the database.

Try a Manual Database Repair

If you have access to phpMyAdmin, you can try these steps:

  1. Login to your hosting account and open phpMyAdmin
  2. Select your WordPress database from the list on the left
  3. You should see a list of database tables, scroll to the bottom of the list and select “Check All
  4. In the dropdown menu that says “With Selected,” choose the option “Repair Table.

This process will try to fix any broken or corrupted tables. Once it has completed, try refreshing your site and see if the error is gone.

Pro Tip: Also, try visiting your website from a new, private window to see if you see the error there.

Restore From a Backup

If repairs don’t work, the best step to take next is to try and restore your database from your most recent backup. Most hosting providers include daily backups and quick restores that can be loaded with just a few clicks.

You should be able to use your host’s backup tool to restore the latest working version, or, if you use a plugin like Jetpack, you can restore a backup from there.

Still not working? No worries! Move on to Step 4 and let’s see if your server is getting overwhelmed.

Step 4: Is Your Server Overloaded?

Even if you have everything set up correctly, your website might still show the “Error Establishing a Database Connection” if it’s getting congested. This can happen when your hosting environment is running low on resources like memory.

What causes an overloaded server?

Oftentimes, servers get overwhelmed with things like a sudden increase in traffic, too many plugins, a backup process or scan running in the background, and even limited resources from a shared hosting plan.

When this happens, it might temporarily shut down the database or run so slowly that WordPress will time out when trying to connect.

How to Fix It

Try logging into your hosting dashboard and look for a page that has resource usage stats like memory, CPU, or MySQL. If any of those are maxed out, that could be the issue.

Next, disable any heavy plugins by renaming their folders with your File Manager. Start with any plugins that are related to:

  • Backups
  • Page builders
  • Security scans
  • Analytics

You can do this by navigating to wp-content/plugins and renaming one plugin folder at a time.

*Note: The example above is using a file manager plugin. It may look different from what you see on your screen.

For example, try renaming jetpack to jetpack_disabled, save it, then refresh your site to see if the error goes away. Don’t forget to change these file names back if the error isn’t due to one of these plugins.

Also, try to clear out any background tasks that appear to be stuck, if your hosting dashboard provides access to those tools.

If you are on a shared hosting plan and your website has grown, it might be time to upgrade your hosting plan or move to a more scalable option like managed WordPress hosting. The more server resources you are using, the more room you are going to need.

If the server is fine and plugins aren’t the problem, let’s head to Step 5, where we’ll look at possible blocks from firewalls or security plugins.

Step 5: Check Your Security Settings

Even if your credentials are correct and the server is working, your security settings or a firewall could be blocking WordPress from accessing the database.

WordPress Firewall PCI Compliance

This could happen if a security plugin flagged and restricted suspicious activity, you recently changed hosting accounts, or a Web Application Firewall is blocking internal requests by accident.

How to Test Your Security Features

If you suspect a plugin is the problem, here’s a safe way to test it:

  1. Open the FTP client or File Manager in your hosting dashboard
  2. Go to the plugin folder: wp-content/plugins
  3. Look for the security plugin’s folder (for example, Wordfence, Sucuri Scanner, etc.)
  4. Rename the folder like you did in Step 4 — add _disabled to the end (ex: wordfence_disabled)
  5. Save and refresh your website

If your website is working again, then the plugin was probably causing the issue. You can log in to your WordPress dashboard and follow these steps:

  • Adjust the plugin’s settings so it doesn’t block internal processes
  • Replace the plugin with a less restrictive plugin
  • Re-enable it later by renaming the folder back to its original name

Still Having an Issue?

If you have already gone through all of these steps and your website still won’t connect, it might be time to have a professional look into this for you. They can take a deeper look and resolve the issue quickly and effectively, as well as prevent it from happening again. Or if you aren’t tech savvy and you need someone else to take a look for you, our team here at Hog the Web can find and locate the issue, and have your website back up and running in no time.

The Permanent Solution

Lets face it: You didn’t sign up to be your own IT department.
But here you are, googling error codes for a quick fix.

Smart website owners know the value of a dedicated WordPress support team. With Hog the Web, we fix your errors and keep your site running smoothly so you can focus on what you do best; grow your business!

Contact us today, and get your 502 Bad Gateway Error fixed FOR GOOD. 

YouTube video

Our WordPress experts pro-actively maintain and monitor your website, fixing urgent issues, handling updates, patching security vulnerabilities, and answering all your questions so you never have to Google another error message again.

Trusted by 150+ WordPress Site Owners.
We’ve been keeping websites alive and thriving since 2015.

5 Star Reviews

Google-logo
upwork-logo
fb-logo

Testimonials

"I can't say enough good things about the Hog the Web team. They're flexible, communicative, and they offer great ideas and advice."
Rachelyn Provencher

Marketing Director

"We've been working with Hog the Web for the past five years and it's been a really good experience for us."
Bruna Franco

Marketing Manager

"What I love about working with the Hog the Web team is the collaboration and creativity."
Megan Green

Marketing Manager

"We will be using Hog the Web for many many years to come, and we highly, highly recommend them for you as well."
Jennifer Robinson

Co-Owner

Website UpKeep Plans & Pricing

  • Monthly
  • Annually

WEBSITE SECURITY SERVICE

$59/mo

$649/year

Corporate-level website security plan for websites of all types. Includes WAF Firewall, Malware Scans and Removal, Vulnerability Scans and Patching, Site Acceleration Cache and more…

  • Anti-Hacker Firewall
  • Daily Malware Scans & Removal
  • Vulnerability Scans & Patching
  • CDN Site Acceleration – Server-Level Content Caching
  • Daily Cloud Backups & Quick Restore
  • INCLUDED: SSL/HTTPS Encryption Implementation

Get Started:

Sign Up Sign Up (One month free with yearly billing)

BASIC UPKEEP SERVICE

$79/mo

$869/year

The Basic UpKeep Service Plan is ideal for your WordPress website if you’re a startup or on a budget. It covers all the Basic Maintenance needs of your site including software and server updates, bug fixes, up-time monitoring, and access to our support team.

  • Unlimited Bug-Fixes
  • Pro-Active Site & Server Updates
  • 24/7 Uptime Monitoring
  • Daily Cloud Backups & Quick Restore
  • Customer Support via Phone, Email, & Chat
  • INCLUDED: SSL/HTTPS Encryption Implementation

Get Started:

Sign Up Sign Up (One month free with yearly billing)

PROFESSIONAL UPKEEP SERVICE


UPKEEP + SECURITY

$119/mo

$1309/year

For all established websites we recommend the Professional UpKeep Service Plan which includes all of the Basic UpKeep Service features PLUS the Bedrock Security Service Features. Never worry about your website again.

  • Anti-Hacker Firewall
  • Daily Malware Scans & Removal
  • Vulnerability Scans & Patching
  • Site Acceleration – Server-Level Content Caching
  • Unlimited Bug-Fixes
  • Pro-Active Site & Server Updates
  • 24/7 Uptime Monitoring
  • Daily Cloud Backups & Quick Restore
  • SSL/HTTPS Encryption Implementation
  • Customer Support via Phone, Email, & Chat

Get Started:

Sign Up Sign Up (One month free with yearly billing)

BUNDLE DEALS, AGENCY PRICING, & WHITE-LABEL PLANS

Contact Us for Pricing
  • To build your own service plan, contact us.
  • Ask us about bulk discounts for multiple websites
  • White-Label WordPress UpKeep Maintenance Plans
  • We also offer WordPress Optimized, and Managed Hosting Plans

Contact Us

Features Comparison Chart

Security Services

Bedrock Security

Maintenance Services

Basic UpKeep

Maintenance & Security

Pro UpKeep

Features
Get Started Get Started Get Started

Anti-Hacker Firewall (WAF)

Our cloud-based firewall detects and blocks any malicious traffic trying to reach your site, including DDoS attacks, Brute Force intrusions, and website malware. This keeps you safe from site infections, and site intrusions.

Anti-Hacker Firewall (WAF)

Daily Malware Scans & Removal

We scan your entire site and database daily for malware and virus infections. If any are found, we clean and remove them immediately and repair any damage they may have caused.

Daily Malware Scans & Removal

Vulnerability Scans & Patching

We scan your site software daily for vulnerabilities that can be exploited by malicious bots allowing intrusion. If any are found, they are patched immediately.

Vulnerability Scans & Patching

CDN Site Acceleration - Server-Level Content Caching

Our Content Delivery Network (CDN) accelerates the loading time of your website by compressing and pre-loading your web pages on distributed servers all around the country. Shorter distances equal faster loading times.

CDN Site Acceleration - Server-Level Content Caching

Daily Cloud Backups & Quick Restore

We take daily backups of your entire website and store them in the cloud (Amazon S3). If an unlikely catastrophe should occur that takes down your site, we can quickly restore it from any previous day to ensure minimal users are affected.

Daily Cloud Backups & Quick Restore

SSL/HTTPS Encryption Implementation

We install and renew an SSL certificate on your domain to ensure your user's data is encrypted from any eavesdroppers. Google gives a 15% boost in search rankings to sites that are encrypted!

SSL/HTTPS Encryption Implementation

Unlimited Bug-Fixes

If any bugs or glitches appear on your site affecting the display or functionality of your site, we fix them immediately so that your users are not affected. We routinely review and test your site manually for issues.

Unlimited Bug-Fixes

Pro-Active Site & Server Updates

Unlike most "Managed WordPress" hosting providers, we routinely install the new versions of your Plugins, Themes and WordPress software to fix glitches, add new features, and most importantly patch security vulnerabilities found in the code.

Pro-Active Site & Server Updates

24/7 Uptime Monitoring

We monitor your website 24/7 to ensure it's up and running. If your website goes down for any reason, we take action right away to get it back online.

24/7 Uptime Monitoring

Customer Support via Phone & Email

We provide you with a dedicated and responsive support team, who are always happy to answer your questions and solve any issues with your website.

Customer Support via Phone & Email
$59/month $649/year $79/month $869/year $119/month $1309/year
Stay Secured
Bedrock Security

Security Services

See what's included

Anti-Hacker Firewall (WAF)

Our cloud-based firewall detects and blocks any malicious traffic trying to reach your site, including DDoS attacks, Brute Force intrusions, and website malware. This keeps you safe from site infections, and site intrusions.

anti-hacker wordpress firewall Anti Hacker Firewall (WAF)

Daily Malware Scans & Removal

We scan your entire site and database daily for malware and virus infections. If any are found, we clean and remove them immediately and repair any damage they may have caused.

wordpress malware scans Daily Malware Scans & Removal

Vulnerability Scans & Patching

We scan your site software daily for vulnerabilities that can be exploited by malicious bots allowing intrusion. If any are found, they are patched immediately.

wordpress vulnerability scans Vulnerability Scans & Patching

CDN Site Acceleration – Server-Level Content Caching

Our Content Delivery Network (CDN) accelerates the loading time of your website by compressing and pre-loading your web pages on distributed servers all around the country. Shorter distances equal faster loading times.

wordpress site acceleration CDN Site Acceleration – Server-Level Content Caching

Daily Cloud Backups & Quick Restore

We take daily backups of your entire website and store them in the cloud (Amazon S3). If an unlikely catastrophe should occur that takes down your site, we can quickly restore it from any previous day to ensure minimal users are affected.

wordpress cloud backups Daily Cloud Backups & Quick Restore

SSL/HTTPS Encryption Implementation

We install and renew an SSL certificate on your domain to ensure your user’s data is encrypted from any eavesdroppers. Google gives a 15% boost in search rankings to sites that are encrypted!

wordpress ssl https encryption SSL/HTTPS Encryption Implementation

Customer Support via Phone & Email

We provide you with a dedicated and responsive support team, who are always happy to answer your questions and solve any issues with your website.

wordpress customer support Customer Support via Phone & Email

$59/month
$649/year
Most Popular
Basic Upkeep

Maintenance Services

See what's included

Unlimited Bug-Fixes

If any bugs or glitches appear on your site affecting the display or functionality of your site, we fix them immediately so that your users are not affected. We routinely review and test your site manually for issues.

wordpress bug fix service Unlimited Bug Fixes

Proactive site & server updates

Unlike most “Managed WordPress” hosting providers, we routinely install the new versions of your Plugins, Themes and WordPress software to fix glitches, add new features, and most importantly patch security vulnerabilities found in the code.

wordpress update service Proactive site & server updates

SSL/HTTPS Encryption Implementation

We install and renew an SSL certificate on your domain to ensure your user’s data is encrypted from any eavesdroppers. Google gives a 15% boost in search rankings to sites that are encrypted!

wordpress ssl https encryption service SSL/HTTPS Encryption Implementation

Daily Cloud Backups & Quick Restore

We take daily backups of your entire website and store them in the cloud (Amazon S3). If an unlikely catastrophe should occur that takes down your site, we can quickly restore it from any previous day to ensure minimal users are affected.

wordpress cloud backup service Daily Cloud Backups & Quick Restore

24/7 Uptime Monitoring

We monitor your website 24/7 to ensure it’s up and running. If your website goes down for any reason, we take action right away to get it back online.

wordpress site acceleration service 24/7 Uptime Monitoring

Customer Support via Phone & Email

We provide you with a dedicated and responsive support team, who are always happy to answer your questions and solve any issues with your website.

wordpress customer service Customer Support via Phone & Email

$79/month
$869/year
Most Beneficial
Pro Upkeep

Maintenance & Security

See what's included

Anti-Hacker Firewall (WAF)

Our cloud-based firewall detects and blocks any malicious traffic trying to reach your site, including DDoS attacks, Brute Force intrusions, and website malware. This keeps you safe from site infections, and site intrusions.

wordpress website firewall Anti Hacker Firewall (WAF)

Daily Malware Scans & Removal

We scan your entire site and database daily for malware and virus infections. If any are found, we clean and remove them immediately and repair any damage they may have caused.

wordpress malware scanning service Daily Malware Scans & Removal

Vulnerability Scans & Patching

We scan your site software daily for vulnerabilities that can be exploited by malicious bots allowing intrusion. If any are found, they are patched immediately.

wordpress vulnerability scan service Vulnerability Scans & Patching

CDN Site Acceleration – Server-Level Content Caching

Our Content Delivery Network (CDN) accelerates the loading time of your website by compressing and pre-loading your web pages on distributed servers all around the country. Shorter distances equal faster loading times.

wordpress site acceleration service CDN Site Acceleration – Server-Level Content Caching

Daily Cloud Backups & Quick Restore

We take daily backups of your entire website and store them in the cloud (Amazon S3). If an unlikely catastrophe should occur that takes down your site, we can quickly restore it from any previous day to ensure minimal users are affected.

wordpress daily cloud backups service Daily Cloud Backups & Quick Restore

SSL/HTTPS Encryption Implementation

We install and renew an SSL certificate on your domain to ensure your user’s data is encrypted from any eavesdroppers. Google gives a 15% boost in search rankings to sites that are encrypted!

wordpress ssl https encryption service SSL/HTTPS Encryption Implementation

Unlimited Bug-Fixes

If any bugs or glitches appear on your site affecting the display or functionality of your site, we fix them immediately so that your users are not affected. We routinely review and test your site manually for issues.

wordpress bug fix service Unlimited Bug Fixes

Proactive site & server updates

Unlike most “Managed WordPress” hosting providers, we routinely install the new versions of your Plugins, Themes and WordPress software to fix glitches, add new features, and most importantly patch security vulnerabilities found in the code.

wordpress site update service Proactive site & server updates

SSL/HTTPS Encryption Implementation

We install and renew an SSL certificate on your domain to ensure your user’s data is encrypted from any eavesdroppers. Google gives a 15% boost in search rankings to sites that are encrypted!

wordpress ssl https encryption service SSL/HTTPS Encryption Implementation

Daily Cloud Backups & Quick Restore

We take daily backups of your entire website and store them in the cloud (Amazon S3). If an unlikely catastrophe should occur that takes down your site, we can quickly restore it from any previous day to ensure minimal users are affected.

wordpress cloud backup service Daily Cloud Backups & Quick Restore

24/7 Uptime Monitoring

We monitor your website 24/7 to ensure it’s up and running. If your website goes down for any reason, we take action right away to get it back online.

wordpress 24/7 up time monitoring service 24/7 Uptime Monitoring

Customer Support via Phone & Email

We provide you with a dedicated and responsive support team, who are always happy to answer your questions and solve any issues with your website.

wordpress customer support service Customer Support via Phone & Email

$119/month
$1309/year
  • Monthly
  • Annually

Answers to Common Website Issues from Our Experts

Frequently Asked Questions

How quickly can you fix my issue?

For websites covered by our UpKeep services, our usual response time for urgent issues is one hour or less. In most cases we are able to resolve the issue in that time frame. 

If you aren’t yet signed up, then we will first need your web hosting login credentials to troubleshoot, so don’t hesitate, reach out to us now!

Can I hire you to just fix this one issue first?

Yes! We also offer our expert website maintenance and support services a-la-carte. In this case, we bill at our normal hourly rate. We would not exceed a pre-approved time limit/budget we set with you, and there is no minimum time so if an issue only takes 10 minutes to fix, then we only bill you for 10 minutes! 

Contact us to ask about our current hourly rates.

How do I fix a bad gateway error (502)?

A bad gateway error happens when a server upstream is acting up. It’s often temporary, but if it keeps happening, it could point to deeper issues with your web hosting provider or plugins causing server resource overages. We can diagnose and fix it fast, just reach out.

bad gateway error 502

What kind of customer support is included in your UpKeep services?

Beyond all the routine maintenance, testing, optimization and security work we handle behind the scenes we are also available to answer any questions you have about how to use your website; 

  • How do I edit the header nav?
  • How do I change the blog sidebar?
  • How can I integrate your newsletter sign up form?
  • How do I add a podcast to my site?
  • Is my site fast enough?
  • Can we improve my SEO?
  • Anything else you can think of!

Our team of WordPress experts is here for YOU, to help empower you to get the most out of your website!

Ready to Breathe Easy?

Whether you’re staring at a white screen of doom or just want to sleep better knowing your site’s protected, Hog the Web has your back.

Get in Touch

We’re here to help you with any questions you may have. Simply drop us an email message using the form below and we will respond you within 24 hours.

Levi-Meeunweberg (1)

Book a Free Consultation

Let’s talk about your next web project and how Hog the Web can plug into your team to deliver unrivaled results.

Pin It on Pinterest