“Error establishing a database connection” after days of site running

I am running WordPress on AWS (Ubuntu). and have a very weird issue, every few days the database crashes and I am getting the “Error establishing a database connection” message. When I restart it with

sudo service mysql restart

Everything works fine, until the next time it happens several days later.

Read More

Any idea what is going wrong?

Thanks

Related posts

Leave a Reply

1 comment

  1. Are you using micro instance? If so, then you are probably running out of memory.
    The workaround is to create a swap as a file.
    This are the steps to do that:

    sudo dd if=/dev/zero of=/swapfile1 bs=1024 count=524288
    sudo mkswap /swapfile
    sudo chown root:root /swapfile
    sudo chmod 0600 /swapfile
    sudo swapon /swapfile
    

    Now edit /etc/fstab file, so that when you restart the system, swap can be mounted automaticaly.

    sudo nano /etc/fstab
    

    And add this in the file:

    /swapfile swap swap defaults 0 0
    

    To get better performance from swap file in AWS you need to do this too:

    echo 0 | sudo tee /proc/sys/vm/swappiness
    echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf