Just had a big little scare when the blog/website you are on showed the dreaded “Error establishing database connection” error message. I’ve had this show up quite a few times and every time it meant that MySQL had gone down (I’ll go into why I think that happened further down). Luckily I was on my laptop (I’ve tried SSH’ing into my web server from my phone and I can tell you, it’s no fun!) and I even had an SSH session open already so I quickly DuckDuckGo’ed (I stopped using Google a long time ago)”restart mysql on Ubuntu server command line” (I never remember even the most basic/essential command line commands. To my horror this did not resolve the problem.
Only now did I take the time to follow the link to the message on WordPress
wp-admin that explained that my database might be corrupted and needing to be repaired. Corrupted databases sound like a big deal and I just now got my wife to post not just one but two long posts, so even restoring from backup was a dreadful forecast, not just because of the effort involved but also having to explain that she would need to rewrite her post. Luckily the solution was explained right there: add
define('WP_ALLOW_REPAIR', true); to my
wp-config.php and reload the page. This gave me a nice page with two options: “Repair database” and “Repair and optimise database”. The first option worked a charm and my website was back online in a jiffy! Just for fun I tried the second option which let me know that my DB was already optimized.
Why does my MySQL keep crashing? The best reason I’ve come up with is that I am a cheapskate and don’t want to pay for a dedicated server to run my database from so it runs on the same Ubuntu instance my web server runs on. I think running Apache2 together with MySQL means that when there are more than one person using the WordPress admin dashboard at the same time my MySQL database runs out of memory and goes down. The solution is simple, especially now that Digital Ocean provides a managed database option. If I wasn’t such a cheapskate that I didn’t want to pay for it. Since both Kay and myself are using the website/blog to post more regularly including about our sailing adventures, I guess it’s time to fork out some more money and keep this baby running smoothly.