I’m hosting my sites with DigitalOcean (referral link) on the smallest VPS with 512 MB Ram. It’s a cheap way of hosting as I can have virtually as many sites I want on the VPS – and in case it is too slow I can easily upgrade it from the control panel. However, I occasionally get an error on my WordPress sites saying “Error establishing a database connection”. I searched around for a solution and finally found that I needed to add a swap file to the server. I’m currently on Ubuntu 14.04 and it turns out that DigitalOcean actually has a tutorial on how to add a swap file on Ubuntu 14.04
After completing the steps in the tutorial the MySQL error doesn’t occur anymore; and in fact it seems like the VPS is even more responsive now. So adding a swap file seems like a big win.
Thanks for your article ! This error can also be triggered by an XMLRPC attack ! in that case, the apache access file logs are full of xmlrpc requests.