Expanding @eternalliving’s mention of tmpfs into a quick and dirty homelab workaround:
Setup:
/etc/init.d/mysql stop
mv /var/lib/mysql /var/lib/mysql.ondisk
Script at /usr/local/ramdb.sh (remember to chmod +x it):
#!/bin/bash
if [ "$(mount | grep mysql)" != "" ] ; then
echo "[>] Backing up database from memory to disk"
rsync -varP /var/lib/mysql/ /var/lib/mysql-ondisk/
exit
fi
echo "[>] Restoring database from disk to memory"
/etc/init.d/mysql stop
echo "[>] Creating ramdisk"
mount -t tmpfs tmpfs /var/lib/mysql -o nodev,size=1G
echo "[>] Copying MySQL directory to ramdisk"
rsync -varP /var/lib/mysql-ondisk/ /var/lib/mysql
echo "[>] Starting MySQL"
/etc/init.d/mysql start
Added to crontab:
@hourly root /usr/local/bin/ramdb.sh
@reboot root /usr/local/bin/ramdb.sh
Works in a LXC container on Proxmox.
Obviously this method carries its risks, and is not suitable for a production environment unless you really know what you are doing and have daily backups in case the database “save” rsync is inconsistent/corrupt.