A one-gigabyte VPS running MySQL, PHP and nginx has no headroom, and the kernel resolves that by killing the largest process — which is MySQL, mid-write.
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
sysctl -w vm.swappiness=10
echo 'vm.swappiness=10' > /etc/sysctl.d/99-swap.conf
Swappiness at 10 means the kernel prefers to reclaim cache before swapping, so the swap is there as a safety margin rather than as a routine part of operation — a server actively swapping is a server that needs more memory, and the file only converts a crash into slowness. Worth pairing with a MySQL configuration that actually fits: the default innodb_buffer_pool_size on a package install is frequently larger than the machine can afford.