Skip to content

Instantly share code, notes, and snippets.

@laurynasl
Created May 2, 2012 09:51
Show Gist options
  • Save laurynasl/2575624 to your computer and use it in GitHub Desktop.
Save laurynasl/2575624 to your computer and use it in GitHub Desktop.
load mysql to tmpfs
When Ubuntu uses upstart, tmpfs can be mounted on /var/lib/mysql just before mysql start.
To do that, copy load_mysql_to_ramdisk to /usr/local/bin/load_mysql_to_ramdisk,
and apply modifications of modification_for_etc_init_mysql to /etc/init/mysql.conf
(I had to modify pre-start script by adding one line to the start,
and to create new post-start script).
#!/bin/sh
case "$1" in
start)
# stop before starting mysql
cp -Rp /var/lib/mysql /tmp/var_lib_mysql
mount -t tmpfs tmpfs /var/lib/mysql -o size=256m
cd /tmp/var_lib_mysql
cp -Rp * /var/lib/mysql/
cd /
rm -rf /tmp/var_lib_mysql
;;
stop)
# stop after stopping mysql
umount /var/lib/mysql
;;
*)
echo "Usage: $SCRIPTNAME {start|stop}" >&2
exit 3
;;
esac
pre-start script
/usr/local/bin/load_mysql_to_ramdisk start
end script
post-stop script
/usr/local/bin/load_mysql_to_ramdisk stop
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment