Skip to content

Instantly share code, notes, and snippets.

@Alexx-G
Created August 20, 2014 08:46
Show Gist options
  • Save Alexx-G/276293c59227746207fe to your computer and use it in GitHub Desktop.
Save Alexx-G/276293c59227746207fe to your computer and use it in GitHub Desktop.
Mount/Umount mysql databases into ramdisk
#!/bin/sh
#stop mysql service
service mysql stop
#mount ramdisk
mkdir -p /tmp/db_ramdisk
mount -t tmpfs -o size=512M tmpfs /tmp/db_ramdisk
#create back-up
cp -ra /var/lib/mysql /var/lib/mysql_bak
mv /var/lib/mysql /tmp/db_ramdisk/mysql
ln -s /tmp/db_ramdisk/mysql /var/lib/mysql
#change permissions for created link
sudo chmod -R 700 /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
service mysql start
#!/bin/sh
#stop mysql service
service mysql stop
#remove link to mysql folder
rm -f /var/lib/mysql
#if copy of folder from ramdisk succeed then remove back-up, otherwise restore folder from back-up
if cp -ra /tmp/db_ramdisk/mysql /var/lib/mysql; then
rm -rf /var/lib/mysql_bak
else
rm -rf /var/lib/mysql
cp -ra /var/lib/mysql_bak /var/lib/mysql
rm -rf /var/lib/mysql_bak
fi
#start mysql service
service mysql start
#unmount ramdisk
umount /tmp/db_ramdisk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment