Solution: Error Establishing a Database Connection in WordPress, PHP, MySQL

By Chongchen Saelee

I never seemed to have this problem before and for the past week or two, my website seems to have been hit by the notorious “Error Establishing a Database Connection” problem with WordPress or MySQL databases in general. These are the steps I’ve been taking to remedy the problem:

  1. Read through any custom PHP coding you might have written to make sure there are no typos, unneeded bloat reference calls and variables, etc. If you’re not a master coder, which I’m not, then it may be your human error. They logic being that the error started popping up only recently because you started tinkering with the setup. Go figure.
  2. So if it’s not your fault, then it may be your server or webhost tinkering on their end. But since we need to have better faith in their competence, let’s not jump to that conclusion yet. If the error is that verbose, that it is a database problem, then you need to access your database backend and see what is wrong. If your databases are corrupted and need to be repaired, then that might fix the problem. But if you have a lot of databases, it’s going to be hard to go through every one of them. You assume it is associated with WordPress, and after you’ve followed their steps (just Google it), and it’s still not fixed, then it might not be a WordPress problem after all.
  3. It may be that you’ve reached somekind of threshold limit on your webhost.
  4. It may be incompatibility issues in new PHP/MySQL software.
  5. So you’re sure you didn’t tamper with WordPress or let it auto-update or whatever, then it must be something else accessing your MySQL databases. Go through your website to see what uses your databases. For me, it was a PHPBB forum I left unmonitored that was getting ass-raped by bots and spam-registering shit ton of accounts. That corrupted or pretty much was clogging up my databases with records. And databases are just binary files on a hard drive (the server) and too many writes defrags that machine. Turns out, once I fixed that PHPBB forum (mind you, it can be any forum software or database app) the error seemed to disappear and my website was blazing fast again.
  6. So there you have it. On the surface, WordPress is nice enough to give you a verbose error message. However, the problem was being caused by another PHP/MySQL software (in my case an unattended PHPBB forum) and that was messing all things up. So once that was fixed, then everything returned by to harmony. At least… I hope it did and will continue to be stable. Wish me luck.

In summary, troubleshoot your website with a holistic approach. If you know you didn’t mess with WordPress or your database, then something else must be wrong. Find the problem and fix it. Your last resort is to blame your webhost, but I’m sure they’re just as human as you and might come to the same conclusion (or if your SOL with a poor customer service webhost, won’t get any help at all).

Hope it helps even a bit. Good luck, webmasters!!! We are a unique breed of trolls.

Tags: , , , , , , , , , , ,

Leave a Reply