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

Advanton USA

MENUMENU
  • Home
  • What is Advanton
    • Create Online Presence
    • What is Website Design?
    • WordPress Tutorials
  • For Contractors
  • Solutions
    • Small Business Website design services
    • Business Website Free
    • Sell Products Online
    • Yodle Alternative
    • Wix Alternatives
    • Marketing for hvac companies
    • Painting Leads
    • Insurance Leads
    • Sales Leads for Flooring Contractors
    • Web Design Company in Maryland
    • Website Design for Clothing Company
    • Website Design for Real Estate
    • Business Banking
  • Business Ideas
  • Success Stories
  • Resources
    • How to guides
    • Small Business
    • Small Business Marketing
    • Market Research
    • online presence
    • US Small Businesses
    • Make Life Better
    • Banking
    • Internet
    • Google My Business
    • Grow with Google
    • World Facts
    • Google Pixel
    • Apple iOS updates
    • Uncategorized
  • Pricing
  • Contact Advanton
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

Filed Under: How to guides

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

Get 100% Local Customers, Local Leads & Income

submit guest post

Contact Us

starbucks franchise
topgolf franchise
toyota dealership franchise
tile contractor los angeles
plumbers boston ma
trucking logistics new jersey

Local & Small Businesses in the U.S.

High Risk Truck and Auto Insurance in U.S.

Insure Quest, Insurance Agency, FL, TX, CA, GA, MD, NJ

Call:813-838-3994

---------------------------------------------

Guaranteed Small Business Loans and Equipment Finance

Ready Finance LLC, New Jersey

Feel free to Call: 201-960-8889

---------------------------------------------

Experienced Employment Attorney Minnesota

Satre Law Firm Minnesota

Call:651-212-4919

---------------------------------------------

Low Cost Trucking and Shipping Company in the U.S.

VJS Logistics

Call:201-463-6520

---------------------------------------------

Solve Relationship Issues and Get what you want in Life

Relationship Coach and Personal Life Coach

Call:804-491-8082

---------------------------------------------

Tile Work South Bay, Los Angeles, CA

Tile Repair and Installation Contractor in Los Angeles

Call:310-748-9118

---------------------------------------------

Customs and Trade Logistics, LLC

Import and Customs Clearance Agent in USA

Call:443-955-6556

---------------------------------------------

VS Remodeling, Boston, MA

Office, Home Remodeling and General Contractor in Boston, MA

Call:617-612-5631

---------------------------------------------

Computer, Laptop and iPhone Reapir in O'Fallon and Saint Peters, Missouri

KinneyKare Computer and iPhone Repair

Call:636-362-4150

---------------------------------------------

Licensed Electrician for Residential and Commercial Work in Boston, MA

AV Electrical Systems

Call:508-494-7323

---------------------------------------------

Tile Installation and Flooring Contractor in Scottsdale, AZ

Ventana Tile and Custom Flooring

Call:760-291-7021

---------------------------------------------

Fire Alarm and Secuirty Cameras installation in Boston, MA

Boston Fire Alarm Inc.

Call:781-559-3238

---------------------------------------------

Body Massage Therapy and Skin care Facials in Brookfield, WI

Skin Deep SPA Wisconsin

Call:262-202-8242

---------------------------------------------

Local Plumbers in Boston, MA

Good Plumbing Boston MA

Call:617-849-3722

---------------------------------------------

Shot Blasting Machine Manufacturers

Maan Global Industries

Footer

About ADVANTON

ADVANTON empowers small businesses with the world’s leading CLOUD solution for local business marketing. Our technology solves one major challenge for every small business and that is acquiring local customers. Over 10,000 small businesses generate business leads and revenues every month. Are you the next?

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 © 2025 — ADVANTON • All rights reserved. • Privacy Policy

  • About Us
  • Advertising on Advanton
  • Contact Advanton
  • sitemap
  • Marketing For Contractors
  • Roofing leads
  • Pest Control Leads
  • Los Angeles Contractor Leads
  • New Jersey Contractor Leads
  • Boston Contractor Leads
  • Houston Contractor Leads
  • Arizona Contractor Leads
  • Maryland Contractor Leads
  • Orlando Contractor Leads
  • Hire Boston General Contractors