Close Menu
Infoceptor
  • Business
  • Finance
  • Technology
  • Health
  • Life
  • More
    • Auto
    • Food
    • Health
    • Home
    • Space
    • Travel

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot
Flywheel Logo

Flywheel review in 2023

June 8, 2023
Travel restrictions in Canada are different depending on where you're traveling from and to. Here's what you need to know before you go.

Canada: Traveling restrictions and what you need to know before you go

May 19, 2024
If you are planning a trip to Spain, there are some travel restrictions that must be taken into consideration.

Spain: Traveling restrictions and what you need to know before you go

May 19, 2024
Facebook X (Twitter) Instagram
Infoceptor
  • Business
    This guide will show you how to determine the value of your business using different business valuation methods.

    How to value you business – The ultimate guide for 2023

    May 9, 2024
    Have you ever thought of starting your own laundry service? Find out how with this easy guide.

    How to start a laundry service company in 2023

    May 5, 2024
    Learn about the best online payment solutions available to you. Check out what’s available, learn their pros and cons, and choose the one that best fits your needs.

    The 15 best online payment solutions in 2023

    April 27, 2024
    Learn how to create powerful backlinks for your website and increase your site's search engine ranking.

    How to build backlinks to your website

    April 25, 2024
    In this beginner's guide, we will show you the steps involved in creating a mobile app.

    Beginner’s guide on how to develop a mobile app

    April 24, 2024
  • Finance
    Learn how to build wealth and financial security. This article will share steps you can take to build a reliable cash reserve that will grow over time.

    Do you want to build wealth? Here are some ways to grow your money

    May 18, 2024
    Want to know your tax bracket? Check out our article for an overview of the different brackets and what you can expect to pay in 2022.

    Understanding IRS tax brackets – here’s what you’ll pay in 2023

    May 14, 2024
    This article will cover the best electric vehicle battery stocks to buy and invest in.

    The 10 best EV battery stocks to buy in 2023

    May 9, 2024
    The 10 most active penny stocks to watch this year is a list of the most active penny stocks ranked by total volume.

    The 10 most active penny stocks to watch in 2023

    May 8, 2024
    These electric car stocks are making a lot of money and you should consider adding them to your portfolio.

    The best electric car stocks to buy in 2023

    May 8, 2024
  • Technology
    Flywheel Logo

    Flywheel review in 2023

    June 8, 2023
    This article provides a list of the top iPhone models available today. Each model is reviewed based on features, specifications, performance, design and price point.

    Top iPhone models we’ve tested and you should get

    May 17, 2024
    Find out everything you need to know about the Apple Airpods Pro, including their price, features and if they're worth buying.

    Are Apple AirPods Pro a great choice in 2023?

    May 17, 2024
    To help you find the best responsive WordPress themes, we analyzed more than 100 themes and found those that are currently trending.

    The best responsive WordPress themes in 2023

    May 16, 2024
    These sympathy gifts make a great way to show you care while they also help your loved ones get through the tough times.

    The 15 best sympathy gifts that will show you care

    May 15, 2024
  • Health
  • Life
    These sympathy gifts make a great way to show you care while they also help your loved ones get through the tough times.

    The 15 best sympathy gifts that will show you care

    May 15, 2024
    Water bottles are a great way to stay hydrated. This article is dedicated to the most popular water bottles of the year!

    The best water bottles of 2023

    May 10, 2024
    Learn 30 weird and fun facts that will make you question everything.

    30 weird and fun facts that will make you question everything

    May 10, 2024
    Find out which cities in the US are the best for quality of life by checking out this article.

    20 best cities for quality of life in the USA

    May 7, 2024
    There are many ways to print your designs on t-shirts. Check out our list of the best printing services that offer top-notch quality at affordable prices.

    The 10 best T-shirt printing services of 2023

    May 6, 2024
  • More
    • Auto
    • Food
    • Health
    • Home
    • Space
    • Travel
Facebook X (Twitter) Instagram
Trending
  • Flywheel review in 2023
  • Canada: Traveling restrictions and what you need to know before you go
  • Spain: Traveling restrictions and what you need to know before you go
  • Do you want to build wealth? Here are some ways to grow your money
  • Our in-depth review of the Always Pan
  • Top iPhone models we’ve tested and you should get
  • Are Apple AirPods Pro a great choice in 2023?
  • The best shower heads of 2023
Infoceptor
Home»Technology»Tutorials»How to fix the error establishing a database connection in WordPress
Tutorials WordPress

How to fix the error establishing a database connection in WordPress

Asih TirtaBy Asih TirtaDecember 12, 202311 Mins Read
Facebook Twitter LinkedIn Reddit Telegram WhatsApp Pinterest Email
Read Infoceptor's guide on how to fix the error establishing a database connection in WordPress.
Share
Facebook Twitter LinkedIn
Fix the error establishing a database connection
  • Solution 1 – Database credentials
  • Solution 2 – Database hostname
  • Solution 3 – Database repair
  • Solution 4 – Database connectivity
  • Solution 5 – WordPress link

The WordPress error establishing a database connection is an error that happens when your WordPress website cannot connect to your WordPress database.

When there is an error establishing a database connection, you will see this screen when you visit your WordPress website on your browser:

The error establishing a database connection page in WordPress.

Don’t panic! The error establishing a database connection is easy to fix and we will show you how to fix it in this guide.

How does the error establishing a database connection happen?

Every WordPress website is made up of two main components:

  • WordPress files
  • WordPress database

Your WordPress files are located under your public_html root directory. Think of your WordPress files as shells that receive data to serve to your website visitors.

public_html is your root directory and contains your WordPress files.

Each WordPress website also has a MySQL database, that is normally located in an application called phpMyAdmin. Think of your database as a system that organizes and stores your website data.

phpMyAdmin contains your WordPress database(s).

Your WordPress database feeds your website data to your WordPress files to make your website work.

The error establishing a database connection happens in WordPress when your WordPress database does not properly connect to your WordPress files, triggering the error screen when you or anyone else visits your website.

Your WordPress database connects to your WordPress installation through a file called wp-config.php (remember that file, it’s important).

Inside of your public_html root directory, locate your wp-congif.php file. If you are looking for the wp-config.php file for a subdirectory, click on the right folder within public_html.

WordPress files are always named the same, so you want to make sure you’re in the right folder.

Inside of your wp-config.php file, you’ll find your database name, username, password, and database server.

Inside of the wp-config.php file, there are four key pieces of information required to properly connect your WordPress database to your WordPress files.

  • Database name (DB_NAME)
  • Database user (DB_USER)
  • Database password (DB_PASSWORD)
  • Database server (DB_HOST)

When you click open your wp-config.php file, you will see these four lines listed under a section called MySQL settings.

Look under the MySQL settings inside of wp-config.php to see your WordPress database credentials.

When the wp-config.php credentials cannot connect to your WordPress database, you will see the error establishing a database connection.

The error establishing a database connection is very common and normally happens when the MySQL credentials in your wp-config.php aren’t correctly put in, the database server on your web hosting company is down, or your WordPress database is corrupted / broken.

Now that you know how the error happens, let’s get to solutions on how to fix the error establishing a database connection in WordPress.

Keep reading to learn how to fix the error establishing a database connection on your WordPress website with step by step instructions.

Fix the error establishing a database connection

Below you’ll find tried and tested fixes to the error establishing a database connection, these solutions will work on any WordPress website and you can perform them on your own.

Solution 1 – Database credentials

You need to make sure the database credentials in your WordPress wp-config.php file match your WordPress database.

Normally the database credentials never change. However, if you’ve recently migrated your website to a new web host, performed changes to your WordPress database, or got hacked, the database credentials may have changed.

To check your database credentials are correct, login to your hosting control panel at your web host, where your WordPress website is hosted.

Go to your File Manager:

Go to your File Manager to access public_html.

Inside of your File Manager, click on public_html:

public_html contains your WordPress website and folders for any addon or subdomain websites.

If you’re fixing your primary domain name, stay in the main public_html directory. If you’re fixing an addon or subdomain WordPress website, click on its folder within public_html.

Once you’re in the correct WordPress folder, select the wp-config.php file, and either click Edit or double click on it to open it up.

Click edit on wp-config.php to view your WordPress database credentials.

Once you’ve opened up your wp-config.php file, scroll down to the MySQL settings and you will see the database name, user, password, and database server listed.

Go to MySQL settings to reference your WordPress database credentials.

Keep your tab open on this page, the next step is to make sure your database credentials match.

Open up a new tab and go back to your hosting control panel main page and click on MySQL Databases.

Click on MySQL Databases to access a list of your WordPress databases.

On the MySQL Databases page, you will find a list of all your existing databases and database usernames. Normally, the database name and database username are the same, however sometimes they can be different. You can verify that by checking the MySQL settings in the wp-config.php file.

Look under the Current Databases section to find your database.

Locate your database under current databases and cross-reference with your wp-config.php file.

If you scroll down, you’ll find the Current Users section, which lists the Database Username and also contains a button to reset the database username password.

Locate your database user under current users and cross-reference with your wp-config.php file.

You can change the database username password to the one you see listed next to DB_PASSWORD in the wp-config.php file, just to make sure they match.

Once you’ve cross-checked and confirmed the database credentials in the wp-config.php file under MySQL Settings and your database credentials match, make sure to save the changes in your wp-config.php file.

Then, open a new tab on your browser and visit your website.

If the error is gone, you’ve solved it.

If you’re still seeing the error establishing a database connection screen on your website, let’s keep troubleshooting.

Solution 2 – Database hostname

If you’ve confirmed that your wp-config.php and database credentials are an exact but still see the error establishing a database connection, it may mean the database hostname is incorrect.

Go back to your wp-config.php file and look at the MySQL hostname, aka DB_HOST.

If you see an IP Address or localhost next to DB_HOST in the wp-config.php file, it’s possible the IP Address or localhost is not the correct hostname.

Check and confirm your MySQL hostname is correct.

If you’re unsure, you can contact your WordPress hosting company and ask them what the correct database hostname is and they will confirm if you can leave localhost or put in a different IP Address for the MySQL hostname.

Once you’ve confirmed the database hostname, make the necessary adjustment in your wp-config.php file, click save, and check your WordPress website.

If you still see the error establishing a database connection, you’ll have to try a different solution.

Solution 3 – Database repair

The error establishing a database connection may also mean your database is corrupted or requires repair.

Database corruption is complex, and this solution isn’t a full proof method for fixing it, however it does run a manual repair from your WordPress application which can solve the error.

To run a manual WordPress database repair, go back to your wp.config.php file and look for the following line:

/* That's all, stop editing! Happy publishing. */

Once you’ve found the ‘/* That’s all, stop editing! Happy publishing. */’ line, add this code snippet right above it:

define('WP_ALLOW_REPAIR', true);

Inside of your wp-config.php, it will look like this:

Put in the WP_Allow_Repair snippet to run a manual WordPress database repair.

Make sure to save changes, and go to the following link:

https://www.yourowndomainname.com/wp-admin/maint/repair.php

Make sure to replace ‘yourowndomainname.com’ with your actual domain name.

You’ll get the following screen:

Click on Repair and Optimize Database to run the database repair process.

If for any reason you don’t see the WordPress repair database page, go to an incognito tab and it should appear.

Click on the Repair and Optimize Database button to run the operation. Make sure not to click away or reload your page while the WordPress database repair runs.

When the repair database operation completes, you’ll get a confirmation message and an important notice telling you to remove the define(‘WP_ALLOW_REPAIR’, true); code snippet from your wp-config.php file.

Once the WordPress database repair process completes, you’ll get a confirmation screen.

Once you’ve removed the code snippet from you wp-config.php file, save your changes, and visit your website from an incognito window.

If the error error establishing a database connection is gone, you’ve solved the problem. However, if you’re still seeing it, let’s look at another possible solution.

Solution 4 – Database connectivity

If you’ve gone through the solutions listed above and still get the error establishing a database connection on your WordPress website, it’s possible the MySQL server at your web hosting company is down or overloaded.

If the server at your WordPress hosting company is overloaded or experiencing downtime, it could create database instability and trigger the error establishing a database connection on your WordPress website.

The most obvious way to verify the problem is to ask or check on your web hosting provider’s status page if they’re experiencing database server issues.

If they confirm database problems, wait until the problem is resolved before visiting your website again.

Another way you can check if the database server at your web hosting company is down or unstable is by going to your hosting control panel and clicking on the phpMyAdmin app:

Check your database connectivity by clicking open the phpMyAdmin app from your hosting control panel.

If you click on the phpMyAdmin app and it doesn’t open, that’s a good indicator that your web host’s database server is down, overloaded, or experiencing intermittent connectivity issues.

If your phpMyAdmin app opens and you’re able to connect to your database, there may be a permissions problem, you can test that our pretty easily.

Go to your File Manager, go to the public_html folder, and create a new .php file called ‘testdatabaseconnection.php’

Create a new file inside of your public_html by clicking the new File button.
Create a new testdatabaseconnection.php file to put in the database connectivity code snippet.

Once the file is created, select it, click “Edit” and put in this code snippet:

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

Once you’ve put the code snippet into the ‘testdatabaseconnection.php’ file, make sure to put your own MySQL database setting username (DB_NAME) and password (DB_PASSWORD).

These are the same ones found in the wp-config.php file.

Make sure to update the username and password in the testdatabaseconnection.php to your own database credentials.

Once you’ve done that, save changes and go to the following URL:

https://www.yourowndomainname.com/testdatabaseconnection.php

Make sure to replace ‘yourowndomainname.com’ with your actual domain name.

If you’re able to load the link on your browser, it means there are no permissions issues on your database user settings.

At this point, you’ll want to go back to Solution 1 and make sure your database credentials are correct inside of your wp-config.php file.

Solution 5 – WordPress link

If you’re still getting the WordPress error establishing a database connection after troubleshooting with the solutions above, there is another fix you can try.

Go to your web hosting control panel and click on phpMyAdmin.

On the left-hand side, click on your database from the list to open up the database tables and locate wp_options

Click on wp_options inside of your WordPress database to verify your WordPress link.

Under the option_name column, you’ll see one row for a siteurl and another row for home. Verify that the correct domain name is indicated in those rows.

Under the siteurl and home rows, check or update your WordPress link to the correct domain name.

If the siteurl and home are correct, you don’t need to make any changes. If they don’t match, you can click on the edit pencil icon and put in the correct domain name.

We hope this guide and step by step solutions have showed you how to fix the error establishing a database connection in WordPress.

If your WordPress website is still showing the error establishing a database connection screen after you’ve troubleshooted, it might be time to ask for some professional help.

You could always reach out and ask your WordPress hosting provider if they can troubleshoot for you or point you in the right direction.

The other option is to hire a professional WordPress developer to dig in and fix the problem for you. You can find WordPress developers on freelancing platforms like UpWork, Freelancer, and Codeable.

People also viewed:

Infoceptor's guide on how to find your WordPress login link.How to find your WordPress login link Learn how to how to increase the maximum upload size in WordPress using Infoceptor's guide.How to increase the maximum upload size in WordPress How to fix the dns_probe_finished_nxdomain error How to speed up WordPress by disabling WP-cron How to fix broken links on your WordPress website
database error error establishing a database connection wordpress connection wordpress database wp database
Share. Facebook Twitter LinkedIn Reddit Telegram WhatsApp Pinterest Email
Previous ArticleBest video editing software in 2023
Next Article Bras that will make you completely forget you are wearing them
Asih Tirta

Asih is a Infoceptor Technology writer, she is passionate about how technology can serve people and improve lives. She helps run code camps for K to 12 to teach young girls how to code and open doors to careers in tech for women.

Related Stories

How to speed up WordPress by disabling WP-cron

February 16, 2024
Infoceptor's guide on how to find your WordPress login link.

How to find your WordPress login link

January 4, 2024

How to fix the dns_probe_finished_nxdomain error

December 17, 2023
Learn how to how to increase the maximum upload size in WordPress using Infoceptor's guide.

How to increase the maximum upload size in WordPress

August 3, 2023

Comments are closed.

Connect
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
  • LinkedIn
  • Reddit
  • TikTok
Don't Miss
Flywheel Logo Reviews

Flywheel review in 2023

By Matthew Drummond

Flywheel is a fast-growing web host that offers high-performance WordPress hosting for agencies, designers, and developers.

Travel restrictions in Canada are different depending on where you're traveling from and to. Here's what you need to know before you go.

Canada: Traveling restrictions and what you need to know before you go

May 19, 2024
If you are planning a trip to Spain, there are some travel restrictions that must be taken into consideration.

Spain: Traveling restrictions and what you need to know before you go

May 19, 2024
Learn how to build wealth and financial security. This article will share steps you can take to build a reliable cash reserve that will grow over time.

Do you want to build wealth? Here are some ways to grow your money

May 18, 2024
  • Auto
    • Auto Reviews
    • Electric
    • Insurance
  • Business
    • Company
    • Government
  • Entertainment
    • Movies
    • Music
  • Finance
    • Credit Cards
    • Crypto
    • Market
    • Personal Finance
  • Food
    • Coffee
    • Drinks
    • Holidays
  • Health
  • Beauty
  • Fitness
  • Food
  • Medical
  • Home
  • Backyard
  • Bathroom
  • Bedroom
  • Cleaning
  • Furniture
  • Home Office
  • Kitchen
  • Life
  • Astrology
  • Family
  • Fashion
  • Outdoors
  • Personal
  • Pets
  • Apple
  • Audio
  • Domain Names
  • Gaming
  • Google
  • Power
  • Reviews
  • Samsung
  • Destinations
  • Gear
  • Services
  • Space
  • Tourism
  • Technology
  • Tutorials
  • Web Hosting
  • WiFi
  • WordPress
  • Travel
  • Shopping
  • Sports
  • Work
  • Stocks
  • Television
  • Web Hosting
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn Reddit TikTok
© 2025 Infoceptor

Type above and press Enter to search. Press Esc to cancel.