• Skip to primary navigation
  • Skip to main content
  • Skip to footer
advanton usa logo

Advanton USA

  • Start
    • How to start a business, A to Z
    • Business ideas
    • Test your business ideaTest your idea with real industry data
    • Choosing a business structure
    • Get an EIN
    • SBA loans
    • Small business grants
    • Business banking
    • Franchises
  • Grow
    • Hiring your first employee
    • Taxes and bookkeeping
    • Keeping customers
    • Financing growth
    • Using AI
    • Industry data
    • Services owners use
      • USPS for small business
      • Every Door Direct Mail
      • USPS vs UPS vs FedEx
      • Yelp for Business
      • Apple Maps listing
  • Free Tools
    • Start
      • Business Idea Reality CheckTest your idea with real industry data
      • Business PlannerName, costs, pricing and a one-page plan
    • Launch
      • Launch your business onlineDomain, website and hosting, step by step
      • Brand & Print StudioCards, flyers, postcards, signs and more
      • Website builderA free website in about 10 minutes
    • Market
      • Marketing HubOnline presence, reviews and lead tracking
      • Local SEO checkerScan your site and fix local rankings
    • Grow
      • Quotes and invoicesProfessional quotes and invoices
      • Cash & Payroll PlannerCash flow, hiring costs and unpaid invoices
      • Mileage logBusiness miles at the 2026 IRS rate
      • Rewards programStamp cards that bring customers back
      • Word to PDFConvert Word documents to PDF
  • Contractors
    • Contractor website builderWebsites for 8 trades, 5 designs each
    • Websites by trade
      • Roofing
      • Remodeling
      • Painting
      • Plumbing
      • Flooring and tile
      • Electrical
      • HVAC
      • Handyman
    • Yard signs and door hangersYard signs and door hangers with a QR code
    • Marketing for contractors
    • Angi vs Thumbtack
  • Local SEO Check
    • Scan your websiteScan your site and fix local rankings
    • Plan service and town pagesScan your site and fix local rankings
    • Generate LocalBusiness schemaScan your site and fix local rankings
    • Business Profile checklistScan your site and fix local rankings
    • Compare with competitorsScan your site and fix local rankings
    • Learn the ranking factorsScan your site and fix local rankings
  • Directory
    • Browse the directoryFind local small businesses
    • Add your businessA free listing in the directory
  • Get Online
    • Launch your business onlineDomain, website and hosting, step by step
    • Free website builderA free website in about 10 minutes
    • Contractor website builderWebsites for 8 trades, 5 designs each
    • Domains and hosting
    • After you buy: help guides
      • Verify your new domain
      • Upload your website
      • Connect your domain
      • Turn on free SSL
      • Set up business email
      • Renewals
Home » How to Fix Error Establishing Database Connection

How to Fix Error Establishing Database Connection

December 5, 2018 Leave a Comment

While managing your WordPress website on a daily basis you may come across few errors but one of the most frustrating one is the one that says ‘error establishing a database connection. It is frustrating because it turns the whole page blank with just a database connection error message.

error establishing a database connection

This error message can trigger by itself sometimes even when you didn’t make any changes to the code or WordPress files as there are several possible causes behind it.

So, let’s dig deeper into this topic and explore all the possible solutions to fix database connection error on WordPress websites.

We suggest you to backup WordPress before you start experimenting with any of the solutions that are mentioned here to fix database error.

What triggers establishing a database connection error?

There are several possible causes that trigger ‘error establishing a database connection’ message as mentioned below:

  • Your Database login credentials are wrong or have been modified and does not match your WordPress database user and password.
  • The database server with your web hosting has stopped or not responding.
  • The database server has been upgraded by the Web Hosting company
  • Your WordPress database been corrupted.
  • Web Hosting Server has some technical issues or errors due to which WordPress is unable to establish connection with the database.
  • There could be other reasons as well that rarely occur.

Possible solutions to fix error establishing a database connection problem

First try to figure out if you are getting the same error message on both the front-end and the Admin area (backend) of your website and if the error message is same then you need to check config.php file for the login credentials mismatch.

It is explained below how to access and modify config.php file for WordPress.

But before we move onto that step let’s take a look at the scenario that you are only getting ‘error establishing a database connection’ message at the backend i.e. WordPress Admin side and in that case you can try repairing your WordPress database to fix the error.

You can do this by adding the following line in your wp-config.php file. Add it just before the line that reads ‘That’s all, stop editing! Happy blogging’.

1 | define(‘WP_ALLOW_REPAIR’, true);

Once you are done with it, you can see the settings by visiting this url: http://www.yourwebsite.com/wp-admin/maint/repair.php

A user does not need to be logged in to access this functionality when that line is added to the wp-config.php file. This is because it is used to repair the corrupt database and a user can often not login when the database is corrupt.

After the database repair is complete, make sure to remove that line from your wp-config.php.

If the above solution fixes the ‘error establishing a database connection’ for you then you can stop here. But in case the problem still persists then continue with the other possible fixes below.

Access and modify config.php file for WordPress.

WP-Config.php is the most important file of your WordPress installation as it contains database connection credentials. It helps in establishing a database connection.

If you changed the root password or updated the database user password, then you will need to make changes in this file as well. First thing you should always check is if everything in your wp-config.php file looks same as below:

1

2

3

4

define(‘DB_NAME’, ‘database-name’);

define(‘DB_USER’, ‘database-username’);

define(‘DB_PASSWORD’, ‘database-password’);

define(‘DB_HOST’, ‘localhost’);

Check your DB_Host value as it not always localhost because many web hosts prefer the localhost IP instead of the ‘localhost’. However, with the most popular WordPress hosting providers such as bluehost, siteground etc. and with some of the best WordPress Web hosting providers ‘localhost’ works.

Try to replace the ‘localhost’ with the IP as below and it will fix the problem.

1 define(‘DB_HOST’, ‘127.0.0.1:8889’);

IP’s may vary for online web hosting services and you should check it with your Web Hosting Provider.

If you have made changes and tested as mentioned above and you are still getting ‘error establishing a database connection’ message then there might be an issue with the web server or database server itself.

Testing the availability of the Web Host (MySQL Server)

Before you get in touch with your Web Hosting Company to resolve the ‘error establishing a database connection’ let’s find out if the MySQL server is available and running.

If your website traffic suddenly goes up then your MySQL server may not be able to handle the load and generates error for the users.

To rule out any doubts you can conduct the connection test by yourself. Access the cPanel through your web hosting account and access phpMyAdmin and connect the database.

If it connects then we need to check if your database user has sufficient permission and for this you need to create a new file ‘testconnection.php’ and paste the following lines of code in it:

$link = mysqli_connect(‘localhost’, ‘username’, ‘password’);
if (!$link) {
die(‘Could not connect: ‘ . mysqli_error());
}
echo ‘Connected successfully’;
mysqli_close($link);
?>

Make sure you replace the username and password with the database username and password of your WordPress database.

If running the above script connects successfully then it means that your user has sufficient permission and there is something else that is wrong that’s triggering the error message.

You need to re-check your wp-config file to make sure that the credentials there are correct. Check for typos as well as that causes errors many times.

In case you are unable to connect to the database by going to phpMyAdmin then it simply means that there is something with the server.

If you see something like this Access denied for user ‘foo’@’%’ (using password: YES) when connecting to the MySQL server through the testconnection.php as mentioned above or you are getting the access denied error when connecting your phpMyAdmin then you it’s time to get in touch with your Web Hosting Company.

These are few of the possible solutions that you can try when getting ‘error establishing a database connection’ message.

Don’t panic if you see that weird connect error message. Just try the above mentioned solutions and it will fix the problem in no time.

How to install WordPress Theme

How to convert pdf to word on Mac

How to migrate WordPress from an old web host to a new one

List of Websites for downloading Elementor Templates for WordPress

21 Best Websites to Download free WordPress Themes

23 Best Web Hosting for WordPress

12 Keyword Research tools for SEO

free wordpress website

Starting or growing a small business? Explore industry data and business ideas by budget, or follow the step-by-step guide to starting a business.

Share this guide

Filed Under: How to guides

Reader Interactions

Leave a Reply Cancel reply

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

Local SEO Check Free: scan your website and see what to fix to rank in local search →

Start and grow

  • Start a business, A to Z
  • Industry data
  • Services owners use
  • Grow your business

Free tools

  • Website builder
  • Local SEO Check
  • Business Planner
  • Quotes and invoices
  • Rewards program
  • Brand & Print Studio
  • All free tools

Get online

  • Launch your business online
  • Domains and hosting
  • Verify your new domain
  • Upload your website
  • Set up business email
  • For contractors

Advanton

  • About
  • Contact
  • Business directory
  • Add your business
  • Back up your work
  • Privacy policy

Advanton Free guides and tools for US small businesses.

Advanton earns money when you buy a domain or hosting through our store. It helps keep our guides and tools free.

Footer

About ADVANTON

Free guides and tools that help small businesses start, launch online, find customers and grow.

Follow us

  • facebook
  • twitter
  • yelp

Our Associations

Contact Us

Email: info[at]advanton.com

From rest of the world, email us: info[at]advanton.com

Copyright © 2026 — ADVANTON • All rights reserved. • Privacy Policy

  • Start
  • Grow
  • Free Tools
  • Contractors
  • Local SEO Check
  • Directory
  • Get Online