• Home
  • MAD
    • IOS Series
    • Android Series
    • Flutter Series
    • Xamarin Series
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
  • Home
  • MAD
    • IOS Series
    • Android Series
    • Flutter Series
    • Xamarin Series
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • MAD
    • IOS Series
    • Android Series
    • Flutter Series
    • Xamarin Series
  • Concept Series
    • Software Design
    • Software Arch
    • GIT & Github
    • System Design
    • Cloud
    • Database Integration
    • Push Notification
    • API Integration
    • Cocoa PODS
  • DSA
  • Interview
  • Tips&Tricks
  • YT
Wordpress

How to Fix “Error Establishing a Database Connection” in WordPress

How to Fix “Error Establishing a Database Connection” in WordPress

Database Connection : While working with wordpress blog , we sometimes face with a common problem and that is not related wordpress design , not related to wordpress theme , even that is not related to any third-party Plugin, That issue exists inside the database itself .

Common error we face is nothing but the “Error establishing a database connection”

Sometimes I think WHY this errror occurs even after installing the wordpress and custom themes and plugins , All these i can install or configure because database is working perfectly.

So where is the issue persist, issue persist within, within database itself and sometimes we injected un-intentionaly.

So let take a ride how these issue persisit and it occurs sometimes but not always.

WordPress uses two main pieces of technology to provide you with all its awesome abilities: PHP and MySQL.

PHP is a programming language. WordPress – the core WordPress files – have been written in PHP. Boring, sorry.

MySQL is a database technology. WordPress uses a MySQL database to store all of your website’s content. This includes your posts, pages, but also the smaller elements, such as the title of your site, the layout of your widgets, the color settings, and etc. Basically, the MySQL database is where every, even the smallest piece of information about your website, is kept.

This is where the error comes into play. The error occurs when, for whatever reason, WordPress cannot access the information in the database via PHP commands. When that happens, WordPress basically doesn’t know what to do next, so the only thing it can say is, “Error establishing a database connection.”

With that being said, there can be a handful of reasons why the error occurs. Some of the more common ones:

  1. Incorrect login credentials. WordPress needs a specific login and password to access the database. If those have changed for any reason then WordPress will no longer be able to fetch anything from the database.
  2. Corrupted WordPress files. The core WordPress files can get corrupted as a result of a failed update, among others. This can include things like failed updates of the plugins, themes, and even the main WordPress software updates.
  3. Corrupted database. This might be a result of a rogue plugin messing up the database internally, a hacker’s attack, a theme failing, and many more.
  4. The database server is down. In some cases, the web server – the server that stores your website files – is run on a different machine than the database. And that separate database server can simply be down for whatever reason.
  5. Too much traffic. Even though this is a good problem to have, it’s still a problem. Specifically, your database might be unresponsive due to a high spike in traffic. For example, maybe one of your posts went viral and now everyone and their dog tries to access your site? Hence the server is not able to handle part of those visits.

How To Fix ?

Get In Touch With Your Web Host Provider

Start by contacting that live chat, say that you’re experiencing an “error establishing a database connection” (paste the phrase), and ask:

if the database server is up and running with no problems, and
if there isn’t any spike in activity or traffic on the server right now.

Check If Your Plugin or Theme Files Haven’t Been Corrupted

For instance, maybe you’ve updated a plugin or a theme, and the whole thing collapsed? Maybe you hooked the site up to an external service? Maybe you hand-edited some of the files?

If any of the above ring a bell, you probably have your culprit. If you haven’t done any of that, skip this step.

Here’s what you can do:

First: connect to your host via FTP. You can do this with a free tool called FileZilla.
Second: Go into “wp-content” and rename the “plugins” folder to something else (whichever other names, as long as it’s not “plugins”):
Third: Go back to your site and see if the error is still there.

Check If Your Database Hasn’t Been Corrupted

The WordPress database is a fairly complex thing, and there are a lot of small cogs that need to stay working together perfectly to avoid trouble. At times, something goes out of place and that’s when you see the error establishing a database connection.

The first thing to check is to go to your WordPress dashboard – YOURSITE.com/wp-admin

If you see the same main error: “error establishing a database connection”, skip this step.

Secondly, if you see something else, pay close attention to what WordPress is suggesting you should do. In its recent versions, WordPress has expanded its problem-solving solutions, so you might see some good advice there. One of the possibilities:

This is actually quite simple. First, connect to your site via FTP once again. Go to WordPress root and download the “wp-config.php” file to your desktop.

Edit this file in notepad, add one extra line at the end (right before “That’s all, stop editing”):

define('WP_ALLOW_REPAIR', true);

Now upload the file back to your site (via FTP) overwriting the old version.

Go to YOURSITE.com/wp-admin/maint/repair.php

Click either of the buttons. Once the automatic repair finishes, go back to your site and see if the error is still there.

If no error, great! But you still need to revert your “wp-config.php” file to its previous state. Remove that new line that you just added and re-upload the file.

Check Your Database Connection Credentials

Normally, those access credentials don’t change on their own. However, you can experience some weird scenarios after making any changes to your site files, the hosting environment, or anything else. In other words, even though it shouldn’t be happening, the access credentials sometimes do change. And with bad access credentials – “error establishing a database connection” happens!

The fix is done in the “wp-config.php” file. We’re talking about these lines specifically:

define('DB_NAME', 'some_db');
define('DB_USER', 'some_username');
define('DB_PASSWORD', 'some_pass');
define('DB_HOST', 'localhost');

Restore The Default WordPress Files

As we mentioned before, the core WordPress files can get corrupted for a number of reasons. Maybe there’s been a hacking attempt on your site, maybe you modified some files by accident, maybe a rogue plugin did the modification.

Go here, and download the newest package to your desktop. Unpack. Browse through the unpacked archive and delete the “wp-content” folder.

Next, connect to your site via FTP, go to the main WordPress root, upload your new WordPress files. Overwrite all the previous files.

Liked it? Take a second to support Ranjan on Patreon!
become a patron button
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 1214 Views
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

Next Post
Previous Post

Support us

mycodetips
mycodetips

Follow us @ LinkedIn 2850+

Subscribe for updates

Join 8,213 other subscribers

Latest Posts

  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
  • r-language
    How can R language be used for data analysis?
  • wordpress-coding-blog
    Guide To WordPress Coding Standards
  • YT-Featured-Algorithm
    What is Algorithm?
  • Frameworks of IOS
    Frameworks of IOS – Part ( I )
  • NSFileManager or NSPathUtilities
    NSFileManager or NSPathUtilities in Objective-C
  • Passing data between view controllers in Objective-C
    Passing data between view controllers in Objective-C
  • structures-classes-enum
    Structures and Classes in swift !
  • control-system-swift
    Control Flow in Swift
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #myQuestions

Android Android Studio API APP Programming Apps blogging CSS DATABASE dsa Features HTML HTML5 installation Interview Questions IOS iPhone javascript Mac objective-c OS Programming quicktips SDK SEO SQL swift Tips & Tricks Tools UI Web Wordpress Xcode

  • SOLID Principles of Software Design
  • Latest features in IOS 16
  • How can R language be used for data analysis?
  • Guide To WordPress Coding Standards
  • What is Algorithm?

©mycodetips.com