How To Fix “Error Establishing A Database Connection” In WordPress

Posted on December 20, 2014 by in Tips & Tricks | 76 comments

How To Fix “Error Establishing A Database Connection” In WordPress

It’s one of a website owner’s worst fears.

You type in your website’s URL… but what greets you isn’t your familiar home page.

Instead, it’s a blank screen. No matter what link you try, everything’s missing, except for the ominous words:

“Error establishing a database connection.”

The longer your website is down, the more traffic you’ll lose. And that could mean lost subscribers, lost customers, and ultimately lost revenue.

But what exactly does that error even mean? And more importantly, how can you fix it and get your website back to normal as soon as possible?

In this article, we’ll go over exactly what the error message means and what could be causing it, and then I’ll walk you through some steps to troubleshooting and fixing the problem.

(Want to skip the analysis and start troubleshooting? Just click here to skip ahead.)

What Does “Error Establishing a Database Connection” Mean?

First, let’s take a look at how WordPress works to display your website, and it’ll become clear why this error is so devastating.

The WordPress software is written using PHP and MySQL. Why two languages? Because all the information that makes up your website is stored in a MySQL database, and WordPress uses PHP to store and retrieve information from that database.

Generally, whenever a page is loaded on your website, it’s built on-the-fly. PHP code is used to access your MySQL database and retrieve every bit of information needed to create the page. There’s a PHP query to access the post title, another to grab the author name, another to retrieve the publication date, and so on.

Back to your error message: “Error establishing a database connection.” This means that for some reason the PHP code was unable to connect with your MySQL database to retrieve the information it needs to build that page.

That’s why this error is often all you see on an otherwise blank page. If you can’t connect to your database, there’s no way to know what to display; no information about your website is available.

What Causes This Error?

While the meaning of the error message is clear, the reasons behind its occurrence often aren’t.

There are many reasons why your website could be having trouble connecting to your database, but they generally fall into three categories:

  1. Your login credentials for your database are wrong. Your database uses separate login credentials (username and password). If those credentials have recently been changed, your website won’t be able to access the database with the old credentials.
  2. Your database is corrupted. Any number of things could cause your WordPress database to become corrupted, from uploading a bad plugin, to lightning strikes to the server (seriously — though luckily that isn’t too common).
  3. The server that hosts your database is down. Your database’s server may be down due to a problem or error on the part of your web hosting company, or you could be experiencing a big traffic spike that your server just couldn’t handle.

So with all these possibilities, how can you narrow down the problem and fix it?

Troubleshooting “Error Establishing a Database Connection”

Subscribe To Our Youtube Channel

1. Determine where the error is occurring

Can you see your website normally, but get the error when trying to access wp-admin? Or maybe your website is down, but you’re getting a slightly different error when you try to login: “One or more database tables are unavailable. The database may need to be repaired.”

These are signs of database corruption.

WordPress has a built-in way to attempt to repair your database, but you’ll have to enable this feature first. To do so, you’ll need to access your wp-config.php file, which contains your WordPress installation settings and configuration.

You can find wp-config in the your root WordPress file directory. You can access it by logging into your cPanel, selecting File Manager, and navigating to the folder where you installed WordPress.

Once you have wp-config open, add this line of code to the bottom:

define( 'WP_ALLOW_REPAIR', true );

This line will enable you to optimize and repair your database by navigating to (just replace “” with your actual URL).

Using wp_allow_repair to repair your WordPress database.

You should see the above screen with two options to repair, or repair and optimize, your database. Feel free to choose either; just note that optimizing will take longer.

Please note that this database repair page is not secure; anyone can access that URL without having to login. Once you’re done repairing your database, be sure to remove the line of code you added to wp-config. This will disable access to the repair page and prevent anyone else from messing with your database.

(Just as a side note, there are other ways available to repair and optimize your WordPress database, including via PHPMyAdmin in cPanel. I wrote a bit about it here: Cleaning Up Your WordPress Database To Optimize Your Website’s Performance)

Keep wp-config open for now until you’re certain the error is resolved and your website is working again. If you’re still getting the same error message, you’ll need wp-config open for the next step.

If this doesn’t apply to you, or if it didn’t work, move on to the next step to continue troubleshooting.

2. Check your database login settings in wp-config

If the above step didn’t work or didn’t apply to you, then the next thing you can do is take a look at your database settings in your wp-config file.

Wondering how your database login credentials could have suddently stopped working? Things like switching hosting companies or changing anything about your database name or user information could cause the error if your wp-config file wasn’t updated to the new information.

You may still have the wp-config file open from the last step. If not, log into your host’s cPanel and open the File Manager. Navigate to the directory where you installed WordPress, and look for a file called wp-config.php. Go ahead and open that for editing.

You’ll see the login credentials for your database, probably near the top of the file. It should look something like this:

// ** 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' );

As you can see, there are four pieces of information WordPress needs to access your database:

  1. The name of the database (“DB_NAME”)
  2. The login username (“DB_USER”)
  3. The login password (“DB_PASSWORD”)
  4. The database host (“DB_HOST”)

If any one of these values is incorrect, WordPress will not be able to connect to the database.

One way to check on your database outside of WordPress is by using PHPMyAdmin, a tool for accessing and editing MySQL databases. PHPMyAdmin is included with most hosting plans, and you can find it in your cPanel dashboard.

Warning: Be very careful using PHPMyAdmin, since you’ll be dealing directly with your site’s database.

Once you’ve logged in to PHPMyAdmin, you will see a list of databases on your server in the left-hand column. Click on the one that matches the name in your wp-config file (it will be the value after DB_NAME, where it says “database_name_here” in the above sample code).

(Don’t see any databases? Contact your hosting company, since the entire problem may be an issue with your server.)

After clicking on your database name, you’ll see the main screen populate with the names of the tables in your database. To make sure this is the correct database, you can find the table named “wp_options” and click on the ‘Browse” option next to it. You should see your website’s name, URL, and your other general settings here. Now you know whether or not you have the correct database name in your wp-config file. If it’s not correct, go ahead and fix it in wp-config.

Now let’s check on the username and password.

There are a few ways to do this, some more convoluted than others. I’ll give you two options.

  1. You can either create a simple .php file to test whether you are able to connect to your database with the credentials in your wp-config file, or
  2. You can just create a new user and password, and update your wp-config file with the new info. You’ll have to do this if #1 fails, so you might just want to skip to this step.

Option 1: Test your existing credentials.

Create a file in your WordPress directory called something like testconnection.php (the name doesn’t matter; just the .php extension). Paste the following code:

$test Connection = mysql_connect('localhost', 'root', 'password');
if (!$testConnection) {
die('Error: ' . mysql_error());
echo 'Database connection working!';

Once you’ve created that file, just navigate to the URL of the file in your browser (e.g. your You’ll see either a successful connection message, or an error with more details.

If the username and password isn’t working, we can just create a new one.

Option 2: Create a new database user and password.

We can do that using a different tool available in cPanel called “MySQL® Databases.” Go ahead and click on that, then scroll down to the heading: MySQL Users: Add New User.” Choose a username and strong password, and make note of them for your wp-config file. Click “Create User.” Now scroll down to the heading “Add User To Database,” and choose your new username and your WordPress database, and click “Add.” Update your wp-config file with the new username and password.

Now your database name, username, and password are all correct. That just leaves DB_HOST.

In most cases, this value will be “localhost,” but it depends on your host’s settings. WordPress has a list of common hosts with their DB_HOST values on their website. If your host isn’t listed there, you can contact your hosting company to ask what value to use.

3. Still getting the error message? Check with your hosting company

If you’ve followed the above troubleshooting steps and your website is still down, it could be a problem on your host’s end. Contact your web hosting company’s support and give them all the details of the error and the troubleshooting actions you’ve taken, and they may be able to help you determine the cause of the error.

Share Your Database Connection Error Stories!

Have you dealt with this common issue on your website? How did you fix it? Did you determine what exactly caused the problem? Share your troubleshooting tips below!

Thumbnail image by Tomnamon /

Premade Layouts

Check Out These Related Posts

Splice Video Editor: An Overview and Review

Splice Video Editor: An Overview and Review

Posted on May 7, 2019 by in Tips & Tricks

Video is a valuable form of content for social media. Unfortunately, creating quality videos is usually a long process that involves moving mobile footage to a desktop app for editing. However, mobile editing is on the rise. Apps such as Splice Video Editor make it possible to efficiently create...

View Full Post


  1. I had once a error because I included interupting php files in my footer. So that can also be te problem

  2. I just skip to number 3 and call my web host… It is usually their fault.

    • I with you. I call my hosting service first which is usually where the problem lies. But if they put it back on me, thanks to KeriLynn and Bernard’s observations, I will know where to look.

  3. Kerilyn, this is an excellent article on a critical topic, and I’d like to add a bit to the conversation for those curious to drill down a little more (fancy speak for us geeks). From an historical perspective, there were these massive (i.e. ‘expensive’) relational database systems from the likes of Informix and Oracle. The language used to insert, delete, update, and query records from these databases became known as ‘Structured Query Language’ or “SQL”.

    As smallish systems emerged, people loved the power and flexibility of the relational databases, but they were just too expensive. Around the mid-1990’s, Ulf Michael Widenius (Monty) from Finland began writing an open-source relational database system which became known as “MySQL”. Of course, open source meant free and those lovers of relational expressions began using MySQL like crazy.

    Today, it is beyond prolific. Like most software, it has evolved enormously and powers millions of web sites and, as Kerilyn pointed out, WordPress has it at the core of its operations.

    Now, on some hosts such as DreamHost, they put the file servers on one machine (where your PHP, CSS, and HTML code reside inside WordPress), and the MySQL server on another. As Kerilyn alluded to, if that particular machine is down, so is your database, even though all the PHP and other code is being served up just fine. Of course, that doesn’t work, as you may know all too well.

    I would squirrel away (and I have) these excellent debugging techniques that Kerilyn graciously shared. If nothing else, it will give you peace of mind and a place to start calmly looking when (not if) you ever encounter the dreaded “Error Establishing a Database Connection”.

  4. Sites do go “down” at times, and in most cases that I’ve experienced it’s from being bombarded by requests from dodgy IPs.

    What I would like to do is somehow have an alternate site or page served up to visitors, when the “Error Establishing a Database Connection” message kicks in.

    Is this possible?

    Sometimes our site/s have been down for hours, and it’s quite damaging. We can’t get into the back end, either, at these times. Being able to offer an alternate, non-database driven area on the site would be helpful.

    Any ideas?

    • You can create a custom db-error.php page for that event.

  5. There could be another reason, your mysql server might have low memory. A recent add on or upgrade to your operating system or WordPress might have changed your memory requirements. Mysql tends to crash when memory is too low for it work. You can see this in your server when you try to start your mysql server but you get an error and can not start it.

    If you can’t switch to a server with higher memory you can setup a swap space or if you already have swap space, increase the size of it.

    Also the magic trick is to watch for clues before these problems happen. I suggest that you use some kind of app level monitoring to watch what is happening with your application. I’m not going to advertise anyone so please Google ‘WordPress application level monitoring’ and choose the service you prefer.

    Safe hosting to you all.

    I’m the cofounder of FREE one click WordPress installation on the Cloud. Yep, I advertised myself but nobody’s perfect;)

  6. Thanks for the detailed explanation!

  7. First and foremost I suggest you NEVER trust your hosting company completely. It is up to you to have a complete off site / server backup of your files and database. Even for those of us who run our own servers and have restore ability from the WHM it is important to have off site backups.

    Nobody is going to have more interest in your website backups and security than you are. If you are a novice I would advise hiring a professional who knows what they are doing to help protect your information.

    WordPress is so easy to initially setup and manage that tons of people are doing it themselves. That is fine for a basic site but when the chips are down you will want to have an experienced WordPress specialist at your side. This isn’t the kind of website a friend of a friend should be helping you with anymore.

    Trust me, I’ve done hundreds of WP sites and hosts are simply a bunch of great guys and gals in tech support. They are not going to lose their livelihoods if your website goes away forever or needs completely rebuilt.

    I’ve seen many database errors and the above article is great as long as you have a good backup and someone that knows how to access your database.

  8. While not a database error, I did run into the equally-dreaded Internal Server Error a few days ago. It happened right after updating to the latest version of Jetpack. It asked me to activate a new feature and BAM, Internal Server Error. Fortunately the main website was up and running, however the admin panel wasn’t accessible. For roughly an hour I ran through all the common troubleshooting techniques. Renaming .htaccess, disabling plugins by renaming the folder, increasing PHP memory to 64MB, replacing the wp-admin and wp-includes folders. I even tried restoring the website to a previous date from my hosts control panel.

    Nothing. I kept receiving the Internal Server Error message.

    As a last resort I shot an email over to my host provider for assistance, hoping they could point me in the right direction. Shortly after sending them a ticket, I grew curious about something. I tried accessing the admin panel in another browser (Chrome) and…it worked. I was equally relieved and frustrated. Relieved because I knew how to fix the issue, and frustrated because I wasted time on something that shouldn’t have happened in the first place.

    By working in Chrome, I knew the issue was with Firefox’s cache. For some ungodly reason Firefox wasn’t updating the cache after resolving the original issue. So yes, I did indeed receive and error message, but it likely resolved itself shortly thereafter. Firefox simply did not update the cache to reflect this, and thus kept showing me the error message. A quick clear of my history and cache solved the issue.

    Annoying, to say the least.

    • Thanks for that comment Evan, saved me what I’m sure would have been another frustrating hour banging head on desk 😛

  9. That’s happen to me twice now – 2 different sites. The first time I panicked and did a lot of Google searches and reading… ended up adding new username & password to database via cPanel MyPhp. Then edited wp-config. All was fine – site came back. Next time it happened months later on another site, I didn’t panic but couldn’t remember what I did the first time. 🙂 Finally figured it out and the new user/pwd trick worked again.

    Good article, wish I read it prior to my first blank screen episode!

  10. Is my comment removed???

  11. Wow – this is the definitive article on this subject in my opinion. I just had this problem earlier this week, and spent hours researching how to fix it. I found bits and pieces of the advice you are giving, but nothing anywhere near this clear. All the others assumed that I already knew what they were talking about.

    I keep good backups using BackupBuddy, and was able to restore the site that way faster than troubleshooting with the incomplete information I was able to patch together. I’m keeping this article in PDF format on my cell phone, where I can access it any time, anywhere.

    Thanks – and a thanks to commenter “Evan” who has an excellent point about checking the site in a different browser after attempting a fix. I actually run a different browser in “private” mode to check results after attempting a fix.

  12. My comment didn’t appear at all after 1 day – are you guys having issues?

    • It just means your comment was blocked by our spam filter. We don’t have the time to go through and re-publish the false positives, and unfortunately anti-spam plugins aren’t 100% accurate.

  13. Hi,

    As always : a nice and comprehensive article about the subject. Thanks for the practical tips.

  14. I monitor my website using Pingdom. It does a string check every 10 minutes to make sure a line of text is visible on the homepage, then sends an email (or optional text message) to me when the site is down. I am using WP-Engine and it never goes down.

  15. From my experience, it was perhaps more than 90% of the times caused by the third mentioned issue: mysql db was down. I solved it by putting up a chron job to restart mysql service every 2 hours. After that, I never had the problem again, really!

  16. Mostly this message is shown when the hosting provider runs an upgrade or system maintenance. After a short period of time it is restored. The best solution is to select a hosting provider in the country you are targeting, because the upgrades and system maintenance occur during the night and will not lose much traffic.

    This line of code
    $test Connection = mysql_connect(‘localhost’, ‘root’, ‘password’);
    has a bug.

    You have to remove the space between $test and Connection.
    The correct is
    $testConnection = mysql_connect(‘localhost’, ‘root’, ‘password’);

    • Thanks for this.

  17. Hello! here’s my problem and if you can help me please write to me 🙂

    Sometimes, when i try to open my webpage ( when i enter adress in browser adress bar, appears just white space nothing more, then after i click again enter then opens the page. will this tutorial help me to solve this problem? Tahnk you very much! 🙂

  18. I just had this error because my hosting company upgraded my MySQL database. I thought I would share the fix just in case it happens to someone else.

    The tech said there were too many spaces at the end of the wp-config file.
    He removed them and it was all good.

    I never touch that file so I don’t know why it would have happened, but I thought I would share what I found.


    • I have the same issue when I upgraded from MySQL 5.5 to 5.6. Site goes down 2-3 times a day. I just tried the wp-config fix and removing spaces at the end and see what happens?

  19. Hi KeriLynn,
    So I have been having some issues with my website database and it involved loading my portfolio pages. When I did some test, I found that there were multiple connection. Can I use the repair method:
    define( ‘WP_ALLOW_REPAIR’, true );

    This will allow me to do a repair and optimization of the site, I was planning on redesigning the site to correct the issue but I am will to try this first. I would love some input on this before I do though.

    Here is the portfolio link:

  20. Hi elegant i am in problem , two month ago i purchase a plan with godaddy manged wp hosting i writen here atleast 44 article every thing is right today i m going to my site for writing a article i receive a bug on home url
    Error establishing a database connection

    and on like this
    Error establishing a database connection
    This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at This could mean your host’s database server is down.

    Are you sure you have the correct username and password?
    Are you sure that you have typed the correct hostname?
    Are you sure that the database server is running?
    If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

    now i try to fix them i read almost article about them. but no found a good and after reading your post i have question… i login my panel in godaddy and i thing may be i fix with upload backup but nothing hapend.
    i try to conatct there support team but after searching k goadaddy have no email support i m upsed
    they provide a phone support but due to low quility english i can’t cotact them.
    is there any sulotion to fix this. because i not done any thing wrong i file or change user pass…i think its be a server down eror
    so guide me how many time to come back server on postion?
    thanx if you help me i bookmark the page….need a quickly responce

    • Hey there, I have been suffering from the same problem. No solution here too!
      So if u come across any information worth sharing, kindly reply.

  21. It’s a great article KeriLynn. But I am a beginner so I don’t want to do these things.
    Recently I started a website from godaddy, and after installing wordpress I got “Error establishing in database connection” 3-4 times after after 1-2 minutes site becomes fine. Now, is there any need to do these things, because currently it’s working fine but like yesterday I don’t know when it will show error.

  22. Hi Keri,

    I’m unable to connect to my phpMyAdmin through cPanel – so I’m guessing it’s a MySQL connectivity issue – right? How do I go about remedying that? Do you know any commands specifically that would reboot phpMyAdmin so my database can connect again?


  23. Recently I have come up against the following weird situation: my WP site loses connectivity with the database, let’s say once every 2-3 days and for a timespan of…maybe 15 minutes, and while the database is unavailable, WP serves the installation page ./wp-admin/install.php,,, then after 15 minutes the site gets back to normal as nothing has happened. I contacted the hosting provider, they said everything seems to be from their point.
    Now, I have 2 questions (if anyone else faced similar incidents):
    1. Could anyone else reinstall successfully my wordpress software while wp-admin/install.php page is displayed? (i read a post written 5 years ago where is said that it may be very likely, but that posts addressed old versions up to 2.8,,, now just wondering if wordpress fixed such an issue, otherwise it could be a serious vulnerability as any visitor will see the my installation page while Mysql database is down!!!
    2. I noticed also that mysql DB is 3 times smaller compared to 3 months ago. In december my database was like 387 Mb, now is like 100 Mb. Is there is possibility that any kind of software upgrade was made on the server that compresses the database? I want to note that besides those short interruptions of up to 15 minutes, the site looks and runs perfectly, no issue.
    Kind regards!!

  24. Thankyou so much for this article.
    Changing the username password worked.

    But still testconnection.php is showing the following error:

    “Error: Access denied for user ‘root’@’localhost’ (using password: YES)”

    Am I wrong somewere??

  25. For all its worth, my problem had to do with the user not having privileges on that database. On the test script above I would add:

    if (!mysql_select_db(‘DB_NAME’) {
    die(‘Cannot Select: ‘ . mysql_error());

  26. Thanks for this. I used this post to investigate my install of WordPress for a new domain. The DNS redirection had worked so it wasn’t that.

    I checked the phpMyAdmin and couldn’t see a Database, so I contacted my hosting provider.

    Turns out it was the Fantastico installer script! I reinstalled with Softaculous and BINGO: Instant WordPress!

    Thanks again.

  27. Thanks a lot for such a good post. I too faced the same problem but reading your blog it has been resolved. Really you are doing a good work.

  28. Thanks for this! I have fixed my site myself.

    Happened to me 4x in 2 days! The first times, my hosting provider fixed it for me, but it keeps coming back. Changed the SQL accounts. It works fine now. I hope it wouldn’t come back. I’m updating the plugins too and deleting the unnecessary ones.

  29. I just ran your test connection code and got the following error:

    Parse error: syntax error, unexpected ‘Connection’ (T_STRING) in /srv/users/serverpilot/apps/xxxxxxx/public/testconnection.php on line 2

    Please help, thanks!

  30. I just followed your troubleshooting article after experiencing this issue. I don’t know how, but the username and password no longer worked. I created a new username and password, plugged it into my wp-config file, and all fixed. Thanks a bunch!

    • I had the same Parse error issue. After some effort, (and not knowing php very well) I determined there’s an extra space in the first occurrence of $testConnection — on ‘line 2’. Should be one word. Odd the author didn’t notice that!

      Got that fixed, now just have to figure out the “Error: Access denied for user ‘root’@’localhost’ (using password: YES)”

  31. This is a great article for the begginner to start with debugging the error. Sometimes too many connection to database also give the same error but at the same time works for many users. Confusing huh! But It happens.

  32. i was with it problem, i enter in cpanel and check wp-config.php


    define( ‘WP_AUTO_UPDATE_CORE’, true );

    // ** MySQL settings – You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define(‘DB_NAME’, ‘nikolay_wptest’);

    /** MySQL database username */
    define(‘DB_USER’, ‘nikolay_wptest’);

    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘.OS4F7uP6)’);

    /** MySQL hostname */
    define(‘DB_HOST’, ‘’);

    it person hacked my wordpress, so i deleted old user, and create new user with new password, and put.

    I my website now are working.

    resume, i was hacked.

    I change password of cpanel for security.

  33. Thank you for this useful information. It really solved my db connection problem.

  34. Thanks for this awesome post !!
    I figured out my error . I don’t know how, but my db_host was reset to localhost, instead of “Localhost”.

    Thanks again !!

  35. My website often have been the error. Error establishing a database connection. After I “Go to WHM > Restart Services > SQL Server” to restart SQL Server, the error is resolved.

    But my website often still have been the error every one or two day. Can you help me resolve the error?

    Thanks alot!

  36. Thank you for this!! Just totally fixed my site going through the troubleshooting steps. You are awesome.

  37. Just wanted to say thanks to the author of this post! Adding a new user to the database worked!

  38. Recently I have transferred from Arvixe to Phi 9 web host.
    Actually I forgot to change the previous host “MySQL Connections Strings” in wp-config.php.
    Now it’s working. Thank you for your great article I really appreciate it! 🙂

  39. Actually, I’m getting “Error establishing a database connection” in my home page only. All other pages are working fine. Please let me know what to do.

  40. Problem solved after connecting to the internet, i do not know what happens why in offline mode database running low and always get error “error establishing a database connection”

  41. Same article i read on wpbeginner. By the by, helpful article.

  42. how to resolve error establish a database connection ?

  43. I’m currently hosting with Hostpapa. Facing a lot of downtime. Most of the time I open my website I see an error i.e “Error Connecting Your Database Server”.

    I talked with the Host, they said everything is running fine from their end. What do to, how to fix this issue. I’m running with WP.

  44. Reall nice article. Thanks.

  45. Thanks for this cool article.

  46. Such a great article.

    Even though it contains technical jargon it is simple enough to understand even for our ‘special’ clients ( because we don’t have difficult ones) who insist on trying to fix their own issues.

    This is my go to article for them. Keep it up!

  47. Thanks for your valuable post ! It works in my website on “Error establishing a database connection” problem.


  48. I tried all your suggestions and still getting the dreaded Database connection error…

    My host informed me that they upgraded “MySQL from the version tree 5.5 to version 5.6 as well as the Apache to 2.4 Version and the PHP releases to 5.5” and this is what started the issue.

    I am at my wits end.. anybody can offer some advice?? Please help!!

  49. Sir Help Me Please
    My Website Is Loading, And Working Fine But I Get Error Establishing Database Connection When I Tried Wp-admin And Again I Reloaded Page 3-10 Times And My Site Is Working Again And Again I Get That Error Unexpectedly And My Whole Site Shows Same But Again After Some Refresh , My Site Is Working Again… Help Me Please

  50. My site mysqld stop but i can’t start
    MySQL only run when reboot server.

  51. So our site is currently down saying Error establishing a database connection and have tried every solution. I have looked into the wp-config.php file to see if it has the correct information and it all does. Next I tried to see if the databse is corrupted by doing the repair trick by adding define(‘WP_ALLOW_REPAIR’, true); and when I go to the link it still gives me the Error. The wordpress repair doesnt show up. Any ideas why? Thanks

    • This might be something you want to troubleshoot with your hosting support.

  52. Hello,

    After my server provider updated the PHP version to 5.5, my wordpress does not work. What file do I need to change? He does not provide any support!

  53. Many Thanks for a very useful guide!
    Our site was hanging exactly as described. Followed the steps with no response
    Tricky bit on the test connection php script because of the extra space in the second reference to $testconnection but once removed this showed the database was down.
    I logged into my hosts (1&1) phpadmin panel and everything looked ok. I clicked into the wp-users table to make sure my login was there. Couldn’t see anything that looked wrong at all.
    I re-tried the website and it magically sprung into life!
    Everything appears normal and I can’t see any problems on the site.
    Looks as if the database locked up although I have several other on this 1&1 package and they were all ok.
    I’ll leave the test script in place for next time!
    Great article for a quick fix – wonder how long it had been down……

  54. If I have wordpress posts on an external page, how do I ensure the page still loads cleanly if the database is down?
    Right now I use an include(‘wp-blog-header.php’) at the top of the external page then do the query loop. If mysql isn’t running the page only shows Error Establishing a Database Connection. I want it to just skip the blog posts if there’s an error.

  55. I’ve tried all of the steps described. but the problem has not been resolved. is this because I have just moved the hosting? so the problem exists on the hosting?

  56. I have the same issue. I don’t why it happened. Most time there wasn’t any problem with database connection. I can suspect that some updates cause a problem. Maybe last wordpress upgrade with some plugins but frankly I don’t know.
    I know only that there is a lot apache process that consuming a lot of memory and when that happens mysql crashes too. I made some improvements but to recover server and some setting changes but frankly I doubt if that helps for a long time. I do have vps hosting but not sure now if it is better solution from shared.
    I see that jetpack using cron. It can be also W3 cache. It usually happens after a week in some period of time and last about 10-24 hours, so it could it. I hope it can help somebody.

  57. Hi,

    I have a portfolio site but it shows me the error message. I’ve tried WP_ALLOW_REPAIR this command but. it’s not working.

    Please check and suggest me

  58. I’ve tried all the steps that are described. but the problems have not been resolved. Is this because I recently moved hosting?

  59. I know only that there is a lot apache process that consuming a lot of memory and when that happens mysql crashes too. I made some improvements but to recover server and some setting changes but frankly I doubt if that helps for a long time. I do have vps hosting but not sure now if it is better solution from shared.
    I see that jetpack using cron. It can be also W3 cache. It usually happens after a week in some period of time and last about 10-24 hours, so it could it. I hope it can help somebody.

  60. Hi there,

    I have been experiencing this ERROR ON A DATABASE CONNECTION” usually in the morning, its not always. How can I prevent that to happen?

  61. Great Article. I get this error all the time – I fixed it my resetting user and password like it said in links below, but it keeps coming back

    Set-up WP on Amazon Web Services using these instructions

    Fixed the error using this link, similar to above:

    My problem is this is becoming a several times a week procedure.

    Anyone else hosting a site on AWS with this problem?

  62. I have weired issues with my wordpress installation.
    In trying to install wordpress I created a database with a unique name. I the config file, I input the required connection field, and i was told that wordpress could connect to my localhost server, but not able to select the database. I had spent several days trying to trouble shoot the problem, when suddenly i created a database with the name ‘test’ and it worked. I have tried several other names for database non is successful other than the name ‘test’. I have not had this issue before although i have not used wordpress in a while, may be it is from my wamp installation. But I dont know what the problem is.
    Best regards.

  63. Oh my god. Thank you SOOOOOOO much for this post.
    I found resources helping with this error that were suggesting I needed to log into my wp-admin backend, which I couldn’t access… because of the error!

    This post saved my website and many, many hours of frustration.
    My host support was basically useless and takes days to respond- no live support. Thanks to this experience, I’m considering changing hosts.

    Just following this post step by step, checking everything, and I was able to get my site back up and running after the last step.

    I can’t adequately verbalize at the moment just how relieved I am that this worked.

    Thank you so much!

  64. Option 1: Test your existing credentials.
    please update the code: ($test Connection) => ($testConnection).
    thank you.

Join To Download Today

Pin It on Pinterest