How to solve Mysql database connection error frequently after wordpress installation?

Posted March 6, 2015 5k views

Recently I have purchased vps and after installing a website on wordpress frequenly I am getting an error about mysql database connection error. Each and every time I need to reboot my server, this is not feasible.

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

The most common reason for this issue is that your MySQL process is exhausting the RAM your droplet has available. This then causes the service to crash. There are three steps you can take to resolve this:

1.) Set up a swap file on your droplet. This should prevent the crashes.
2.) Upgrade to a larger droplet with more RAM available.
3.) Optimize your MySQL and other services.

by Justin Ellingwood
Swap space can be used as an "overflow" area for your system when you run out of RAM. The operating system can store data that would normally be kept in RAM on the hard drive in a specially formatted file. In this guide, we'll demonstrate how to create and use one of these files in Ubuntu 14.04.

@ryanpq why does this seem to be a continuous problem for wordpress installs on DO? I haven’t seen this issue across other hosts

  • Because droplets use SSD drives no swap partition is enabled by default on droplets as it is when installed on spinning disks. The problem here is that on a 512MB droplet the MySQL process attempts to use more RAM than is available on that droplet size and since there is no swap file to overflow into when physical memory is exhausted the process is killed.

@ryanpq I just enabled a swapfile on one of my droplets. Since the error seems to occur randomly (not at times of high load) I’m not sure if doing this made a difference or not. Is there a way to stress test the effectiveness of an enabled swapfile? Thanks

  • It can’t be swap file and memory, I have the same thing happen on intermittent basis, my drive has 5 wordpress sites and 2gb of memory and a swap file.

    Very irritating!