# Ugh WordPress database crashes

- Link: https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/
- Published: 2020-07-11T11:00:58-07:00
- Author: rich

Ive been trying to be cheap with my DigitalOcean WordPress installation. I use a
$5/month 1GB memory droplet which works pretty well. The problem is that if you 
run out of physical memory, then MySQL will crash and you get the dreaded, “No database
connection message”.

Here is what I’m doing about it:I created a swapfile since I have 25GB, this will
make it slower, but the crashes are less likely. with 1GB. of memory, the default
is no swapfile for performance reasons and it’s not so great for the SSDs that are
in the shared server. It’s not super complicated, you basically create file wit

    ```wp-block-preformatted
    sudo fallocate -l 1G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    # In my case, I had forgotten to update /etc/fstab
    echo '/swapfile swap swap defaults 0 0' > /etc/fstab
    shutdown now -r
    ```

With the [free](https://www.binarytides.com/linux-command-check-memory-usage/) command,
you can see how much memory is being used. In my very unused WordPress, it is 98MB
free, so not very much and 262MB available if you kick out the caches.

But to get going right away, you need to restart apache2 and [restart mysql ](https://www.digitalocean.com/community/questions/how-to-automatically-restart-mysql-when-it-crashes-on-ubuntu-wordpress-18-04)
with status checking and then a restart

    ```wp-block-code
    # see what the status of the two services are
    sudo service apache2 status
    sudo service mysql status
    # restart as usually mysql has crashed
    sudo service apache2 restart
    sudo service mysql restart
    # If this doesn't work you can try a full shutdown
    sudo shutdown -r now
    ```

But the right long term solution is to migrate to a JAMStack like [Hugo](https://gohugo.io/tools/migrations/)
and then get free hosting at Netlify. They make it easy to migrate and all the code
is now checked into GitHub which is way better.

### Share this:

 * [  Mastodon ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=mastodon)
 * [  LinkedIn ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=linkedin)
 * [  Facebook ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=facebook)
 * [  WhatsApp ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=jetpack-whatsapp)
 * [  Email ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?subject=%5BShared%20Post%5D%20Ugh%20WordPress%20database%20crashes&body=https%3A%2F%2Ftongfamily.com%2F2020%2F07%2F11%2Fugh-wordpress-database-crashes%2F&share=email)
 * [More](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/#)

 * [  Telegram ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=telegram)
 * [  Print ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/#print?share=print)
 * [  Pinterest ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=pinterest)
 * [  Tumblr ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=tumblr)
 * [  X ](https://tongfamily.com/2020/07/11/ugh-wordpress-database-crashes/?share=twitter)

### Like this:

Like Loading…
