Facebook-f X-twitter
EncodeByte
Need Help!
  • How-To
    How-ToShow More
    How To Redirect Old Website To New Domain Without Losing SEO | 301 Domain Redirect
    By
    Franchbabu
    How to Fix the “Windows Cannot Be Installed to This Disk” Error
    By
    EncodeMore
    How to Check Your Laptop’s Battery Health: A Step-by-Step Guide
    By
    EncodeMore
    How to Become a Freelancer in 2025: A Comprehensive Guide.
    By
    EncodeMore
    How to Activate Windows Legally and For Free (100% Working)
    By
    EncodeMore
  • Web Development & Coding
    Web Development & CodingShow More
    How to Become a Freelancer in 2025: A Comprehensive Guide.
    By
    EncodeMore
    Top In-Demand Freelancer Niches for 2025 – Fast Growth Ahead!
    By
    EncodeMore
    🚀 10 Reasons Why Hostinger Is the Best Web Hosting Platform for Speed, Security & Affordability
    By
    Franchbabu
    How to Add “Made with ❤️” to Your WordPress Footer (No Plugin Needed)
    By
    EncodeMore
    WordPress Redirect After Login: How to Set It Up
    By
    EncodeMore
  • Code Snippets & Scripts
    Code Snippets & ScriptsShow More
    How to Hide a Class in WordPress (Easy CSS & Admin Tips)
    By
    EncodeMore
  • Website Design & UX
    Website Design & UXShow More
    10 Web Design Mistakes That Are Killing Your User Experience (and How to Fix Them)
    By
    Franchbabu
  • Make Money Online
    Make Money OnlineShow More
    How to Become a Freelancer in 2025: A Comprehensive Guide.
    By
    EncodeMore
    Top In-Demand Freelancer Niches for 2025 – Fast Growth Ahead!
    By
    EncodeMore
    Website related skillsets that you shoud have
    By
    EncodeMore
    Top Sites Like Fiverr: The Best Fiverr Alternatives for Freelancers
    By
    Franchbabu
    Best Telegram Channels For Free Paid Courses
    By
    Franchbabu
  • 🤩 Trending:
  • How-To Guides
  • WordPress & Website Development
  • Web Development & Coding
  • Windows & Software Fixes
  • Tech Tips, Tools & Tutorials
  • Computer Tips & Tricks
Font ResizerAa
EncodeByteEncodeByte
Search
  • How-To
  • Web Development & Coding
  • Code Snippets & Scripts
  • Website Design & UX
  • Make Money Online
Follow US
Made by ThemeRuby using the Foxiz theme. Powered by WordPress
WordPress & Website DevelopmentHow-To Guides

How to Fix “Error Establishing a Database Connection” in WordPress [STEP BY STEP]☑️

Last updated: November 7, 2022 8:36 pm
By
Franchbabu
Share

The issue establishing a database connection in WordPress will be fixed in this article today.

When WordPress is unable to connect to the database, this error occurs. It might be challenging for novices to troubleshoot your WordPress database connection because of the variety of factors that can affect it.

Contents
Table of ContentsWhat does the WordPress error “Error Establishing a Database Connection” mean?What are the most frequent reasons for “Error Establishing a Database Connection”?How to fix error establishing a database connection in WordPress?Repair WordPress DatabaseIdentify the status of your database server.Other Options That Users Have Found SuccessfulContact the Web Hosting Provider

Table of Contents

  • What does the WordPress error “Error Establishing a Database Connection” mean?
  • What are the most frequent reasons for “Error Establishing a Database Connection”?
  • How to fix error establishing a database connection in WordPress?
  • Repair WordPress Database
  • Identify the status of your database server.
  • Other Options That Users Have Found Successful
  • Contact the Web Hosting Provider

What does the WordPress error “Error Establishing a Database Connection” mean?

A faulty database, an unresponsive database server, or inaccurate database information in your WordPress settings might all be the root of the “Error establishing a database connection” problem.

All of your content and other website data are stored by WordPress in a database. Each time someone accesses your website, it establishes a connection to the database.

You’ll encounter the “Error establishing a database connection” error if any of these details are off and WordPress is unable to connect to your database server. It is one of the most typical WordPress mistakes that users encounter.

What are the most frequent reasons for “Error Establishing a Database Connection”?

The error might appear in several distinct contexts. Among the most frequent are:

  • Incorrect database credentials in the configuration file – The most common cause of a broken database connection is incorrect database credentials. If the database name, username, password, or hostname are incorrect, the website will fail to connect to the database and receive “Error establishing database connection”.
  • Incorrect website URLs, wrong website URLs may be the root of the “Error establishing a database connection” error.
  • Corrupted WordPress files is another factor that might be causing your website to display the “Error establishing a Database Connection” warning. This might be the result of malware infestation, an unsuccessful upgrade, or an unsuccessful file transfer while manually relocating your site.
  • Database corruption. A WordPress MySQL database holds a large amount of data. The mistake in question might occur if any portion is removed or corrupted. Corruption can occur as a result of manually meddling with the database, but it can also occur as a result of routine use. Despite the fact that MySQL is fairly resilient, nothing is flawless, and faults do occur.
  • The database server is down or overloaded.

How to fix error establishing a database connection in WordPress?

To resolve this issue, we must examine two components: the MySQL database and the wp-config.php file.

The following information is used by WordPress to connect to the database.

  • Database name
  • Database username
  • Database password
  • Database server

This data is saved in your WordPress configuration file, wp-config.php. You simply need to ensure that the information in wp-config.php corresponds to the MySQL database.

Step::1 Login to your cPanel

Step::2 Go to MySQL Database

By pressing here, you will be sent to your hosting dashboard’s database management page. The username and database name are available at this location.

Step::3 In a new tab open File Manager section in your cPanel

Step::4 Click on public_html and find wp-config.php file(if your WordPress is installed directly in your domain otherwise go to the relevant Folder where you have installed WordPress and look for wp-config.php file)

Step::5Click over wp-config.php file and choose Edit to look for all the information like database name, database username, database password etc..

You’ll be looking for the following lines in the wp-config.php file.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Verify the login, password, and database host information, as well as the database name.

Once your database name, username, and password have been verified, you may modify them if necessary in your wp-config.php file.

Visit your website once again after that to determine whether the database connection error has been resolved.


Repair WordPress Database

If you’re experiencing a different issue on the WordPress admin, for example, “One or more database tables are inaccessible. If the database has to be repaired, you must fix your database.

You can do this by adding the following line in your wp-config.php file. Just above the line “/* That’s all, stop editing! Happy publishing. */”, add the following code:

	
define('WP_ALLOW_REPAIR', true);

Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php

It should be noted that the user does not have to be logged in to access the database repair page. Once you’ve finished fixing and optimizing your database, delete this code from wp-config.php.


Identify the status of your database server.

If everything appears to be in order but WordPress is still unable to connect to the database, your MySQL server may be down.

A server experiencing high traffic may be the cause of this. Basically (particularly if you are using shared hosting), your host server is simply unable to manage the traffic.

Your website will start to load very slowly, and for certain people, it could even produce an error. Asking your hosting company if your MySQL server is responsive over the phone or in a live chat session is thus the best course of action.

If your SQL server is down, you may verify it by looking at any other websites that are hosted on the same server.

If you don’t have any other websites hosted on the same account, just head to your hosting panel, try to enter phpMyAdmin, and connect the database there.

If you are able to connect, we must check your database user’s permissions. The following code should be pasted into a new file called testconnection.php:

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

Be careful to change the password and username. This file is now available for web browser viewing and upload to your website.

If the script was able to connect, that suggests your user has the necessary permissions and something else is wrong.

Check your wp-config file once again for errors and to confirm that everything is properly.


Other Options That Users Have Found Successful

You can attempt these extra actions if the troubleshooting advice provided above did not resolve the database connection problem on your website.

Inspect the WordPress Site URL in the Database

You won’t be able to log in to the dashboard where the website’s URL is specified because of the problem. However, you may change the tables where these parameters are specified using phpMyAdmin.

Try using phpMyAdmin to modify the WordPress site’s URL. Simply choose your WordPress database in phpMyAdmin by going to the dashboard of your hosting account.

After that click on the SQL menu on the top and enter the following MySQL query.

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'

Don’t forget to provide your own site URL and change wp_options to your own table name as you may have changed the WordPress table prefix.


Contact the Web Hosting Provider

You might need to get in touch with your web hosting firm if everything else fails. Any reputable WordPress hosting provider will assist you in identifying the issue, send you in the correct path, or even resolve it for free.

Hope your WordPress site is fixed now, congrats…

Thanks for Reading this article !!!

Share This Article
Facebook Whatsapp Whatsapp LinkedIn
Leave a Comment

Leave a Reply Cancel reply

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

Popular Categories

Themes & Customization

1 Article

Troubleshooting & Fixes

1 Article

WordPress Tips & Tricks

6 Articles

WordPress Tutorials

5 Articles

Must Read

WordPress & Website DevelopmentHow-To Guides

How to Create a Private/Password Protected Post or Page in WordPress

How-To GuidesSEO Tips & StrategiesWordPress Tutorials

How To Redirect Old Website To New Domain Without Losing SEO | 301 Domain Redirect

Computer Tips & TricksHow-To Guides

How to Repair a Bad Hard Disk (Hard Disk Low Level Format)

How-To GuidesTech Tips, Tools & Tutorials

How to Remove URLs From Google Search

  • I need help with …

Starting a Blog

WordPress SEO

WordPress Performance

WordPress Errors

WordPress Security

Got A Question?

Need Expert Help?
Let CodeXcool power up your website with
custom WordPress design, speed optimization, and SEO!
🚀 Get Started

You Might also Like

15 Best WordPress Tips For Beginners
WordPress Tips & TricksWordPress Tutorials

WordPress Beginner Tutorial | 15 Best Tricks in 2025

Web Development & CodingWordPress & Website Development

The Ultimate WordPress Security Guide – Step by Step (2024)

How to Become a Freelancer in 2025: A Comprehensive Guide.

How To Recover Your Deleted Facebook Messages in Easy ways…

EncodeByte

© 2025 EncodeByte – Discover expert tech tutorials, coding guides, troubleshooting solutions, and free tools. Simplify technology, build smarter, and learn faster with us.

About Us / Privacy Policy / Contact Us

Latest News

  • Coming Soon
  • Coming Soon
  • Coming Soon
  • Coming Soon

Services

  • Coming Soon
  • Coming Soon
  • Coming Soon
  • Coming Soon

Looking for custom web development or maintenance?

Check out our parent team at [CodeXcool.com] 🚀
— Let's build together!
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?