How to fix the error ‘establishing a database connection’ in wordpress


Admit it, this error message looks quite serious. There’s no design, no familiar WordPress site elements, just text:


First off, stop panicking!

We know that you’re probably a bit scared right now, but let us assure you that this problem can be fixed và any permanent damage can be prevented. In fact, the error establishing a database connection is quite common.

Bạn đang xem: How to fix the error ‘establishing a database connection’ in wordpress

Understanding The Problem

As much as we don’t want to play Captain Obvious here, the nature of the error is self-explanatory – it’s an error establishing a database connection.

Here’s what it means exactly:

WordPress uses two main pieces of công nghệ to provide you with all its awesome abilities: PHP and MySQL.

PHP is a programming language. WordPress – the vi xử lý core WordPress files – have been written in PHP. Boring, sorry.

Putting the two together, WordPress uses PHP commands to lớn connect khổng lồ the MySQL database, get the information it needs, and then display everything on the screen.

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 bởi 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:

Incorrect login credentials. WordPress needs a specific login and password to lớn access the database. If those have changed for any reason then WordPress will no longer be able to fetch anything from the database. Corrupted WordPress files. The chip 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, và even the main WordPress software updates. Corrupted database. This might be a result of a rogue plugin messing up the database internally, a hacker’s attack, a theme failing, và many more. The database vps is down. In some cases, the web vps – the hệ thống that stores your trang web files – is run on a different machine than the database. & that separate database server can simply be down for whatever reason. Too much traffic. Even though this is a good problem to have, it’s still a problem. Specifically, your database might be unresponsive due khổng lồ a high spike in traffic. For example, maybe one of your posts went viral và now everyone và their dog tries to access your site? Hence the server is not able to handle part of those visits.

How to lớn Fix “Error Establishing a Database Connection”

Since we value your time, we’re going to first recommend a path that’s the most likely lớn fix the problem for you quickly. Then, we’ll dig deeper and show you how to vị all the fixes on your own manually.

Step 1: Get In touch With Your web Host Provider

Contacting your website host support is always a good idea…

It’s safe to lớn assume that if your site was working just a minute ago (or a day ago) and now it isn’t then the fault can be on your website host’s end.

All quality hosts these days offer some khung of fast-reacting support, usually through live chat.

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

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

In most cases, if you tell them what sort of error you’re having, they will either let you know what the cause is exactly, or they will even fix it for you.

Most importantly, they will let you know if your database is alright and whether or not there’s any suspicious activity on the server.

If the fault is not on their end (the server is operational & there are no spikes in traffic), và they don’t want khổng lồ help you, proceed to lớn step 2:

Step 2: kiểm tra If Your Plugin or Theme Files Haven’t Been Corrupted

Your WordPress files might get corrupted as a result of a couple of misfortunate events.

For instance, maybe you’ve updated a plugin or a theme, and the whole thing collapsed? Maybe you hooked the site up khổng lồ 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:

In order to connect, you need a login & a password lớn your FTP account. If you don’t know what/where those are, the easiest way khổng lồ get them is to tìm kiếm through the initial emails that you got from your website host when you first signed up. Alternatively, you can ask the live chat support representative lớn give you those details.

Having these, connect lớn the server and navigate lớn the WordPress root folder. It’s usually called “public_html” or “www” or you might be in it already once you establish the FTP connection.

The rule of thumb is that if you can see sub-folders lượt thích “wp-content” and “wp-admin” then you’re in the WordPress root. Example:


Second: Go into “wp-content” và rename the “plugins” folder to something else (whichever other names, as long as it’s not “plugins”):


Third: Go back khổng lồ your site & see if the error is still there.

If not, you now know that it’s been caused by some plugin. Go back lớn FTP, rename the folder back khổng lồ “plugins”. Go in it, and change the thư mục names of the individual plugins, one by one. The easiest way to do this is to địa chỉ an underscore at the end: “_”


Keep coming back khổng lồ your site to lớn see when the error gets triggered or vanishes. Once you’ve narrowed it down khổng lồ one specific plugin, you have found the troublemaker. Either delete it or go online khổng lồ see if the solution has been documented.

If the error is still there even after renaming the “plugins” folder, go through the exact same process with the “themes” folder.If that doesn’t help, rename both folders back to “plugins” and “themes”. The error is caused by something else.

Xem thêm: Tổng Hợp Cách Xử Lý Khi Bật Máy Tính Để Bàn Không Lên Màn Hình Hiệu Quả

Step 3: kiểm tra If Your Database Hasn’t Been Corrupted

The WordPress database is a fairly complex thing, và there are a lot of small cogs that need to stay working together perfectly khổng lồ 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 kiểm tra is lớn go to your WordPress dashboard –

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

Secondly, if you see something else, pay close attention khổng lồ 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.

Another possibility is that you’ll see a message starting with “One or more database tables are unavailable <…>” This means that it’s you who needs khổng lồ “repair” the database.

This is actually quite simple. First, connect khổng lồ 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, địa chỉ one extra line at the over (right before “That’s all, stop editing”):

define("WP_ALLOW_REPAIR", true);Now upload the tệp tin back to your site (via FTP) overwriting the old version.

Go to lớn

This is what you should see:


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

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

If the error’s still there, the next step is:

Step 4: kiểm tra Your Database Connection Credentials

As we mentioned, WordPress uses a specific username & password lớn connect to lớn the database. 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 bởi vì change. Và 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");They hold all the details that WordPress needs to lớn connect lớn the database. If any of these are wrong, no connection will be established.

Note that there is a manual way of fixing this issue, but it honestly requires multiple steps và can be really confusing based on the website host you use và the interface they employ. In other words, anything we’d say there would still only be applicable khổng lồ a small range of users who just happen lớn be using the same host as we are, so we have a much more universal solution for you:

Take those four lines from the “wp-config.php” file, simply copy them to the clipboard, contact your web host support again, paste those lines in the chat window & ask if the details are correct for you to lớn be able lớn connect lớn your database.

The representative will check everything, và come back lớn you with some feedback. Most often, they will provide you with the correct details in case anything has been changed.

All you need to bởi is take the new credentials and put them in your “wp-config.php” file where the old ones used khổng lồ be.

define("DB_NAME", "some_db"); /* this is the name of your WordPress database */define("DB_USER", "some_username");define("DB_PASSWORD", "some_pass");define("DB_HOST", "localhost"); /* this is the website address of your database hệ thống */Finally, re-upload the tệp tin via FTP.

At this stage, you can go back khổng lồ your site and see if the error has been fixed.

If not, we have one final step for you:

Step 5: Restore The mặc định 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.

Whatever it might be, you can still restore the default, native files of WordPress. The easiest way to vày that is to just tải về a clean version of WordPress from & copy it over the one you have right now.

Go here, and download the newest package khổng lồ your desktop. Unpack. Browse through the unpacked archive & delete the “wp-content” folder.

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


When the upload is done, go back lớn your site và see the effect.

This is a last resort kind of fix. If this doesn’t help, you will have no other choice than coming back to lớn your web host support line, tell them everything that you’ve done, and asked for help. At this stage, you’ve basically exhausted everything you could vì to fix the issue yourself & it’s the host’s turn khổng lồ solve it. You’re paying your hosting bills after all, aren’t you?

How to lớn Avoid This Error In the Future?

While there isn’t a 100% fail-proof way khổng lồ protect your site against any error establishing a database connection, there are two main elements that you should have in your insurance puzzle khổng lồ be at least 90% safe:

Chuyên mục: Domain Hosting