Skip to content

Instantly share code, notes, and snippets.

@juliendsv
Created September 17, 2012 13:32
Show Gist options
  • Save juliendsv/3737284 to your computer and use it in GitHub Desktop.
Save juliendsv/3737284 to your computer and use it in GitHub Desktop.
Speedup mysql by using RAMDISK
#!/bin/bash
sudo mkdir /db/tmpfs
sudo mount -osize=256m tmpfs /db/tmpfs -t tmpfs
sudo chmod 777 /db/tmpfs
# IMPORTANT edit your /etc/apparmor.d/usr.sbin.mysqld
# to match your new path
# so /var/lib/mysql -> /db/tmpfs/mysql/ (there must be 2 links)
# Then restart apparmor /etc/init.d/apparmor restart
# You must have stop properly you mysql instance before copying this
sudo cp -r /var/lib/mysql /db/tmpfs/mysql
sudo chown -R mysql:mysql /db/tmpfs/mysql
sudo service mysql stop
sudo service mysql start
# Then modify /etc/mysql/my.cnf
# update datadir like this :
# datadir = /db/tmpfs/mysql
#
# To have persistent tmpfs with reboot put the following into /etc/fstab. On this system the mysql user is uid/gid of 27, yours might vary so
# adjust accordingly.
# tmpfs /db/tmpfs tmpfs rw,uid=27,gid=27,size=256M,nr_inodes=10k,mode=0755 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment