If you have some RAM to spare and want to speed up MySQL a little, you can create a RAM disk for MySQL’s temporary disk tables. In Ubuntu Server, the MySQL process is being watched by AppArmor which prevents us from using a custom tmpdir unless the AppArmor configuration is changed accordingly. This post shows how to to it.
Create a new mount for our RAM disk:
mkdir /mnt/ramdisk
Edit /etc/fstab and allocate some RAM for the RAM disk:
tmpfs /mnt/ramdisk tmpfs rw,mode=0777,size=512M 0 0
Edit /etc/apparmor.d/local/usr.sbin.mysqld and add:
/mnt/ramdisk/ r, /mnt/ramdisk/** rwk,
Edit /etc/mysql/my.cnf and change set the tmpdir to your new RAM disk:
tmpdir = /mnt/ramdisk
That’s it. Reboot the server and the RAM disk will be used for temporary disk tables. Obviously, the RAM disk can be used for other purposes as well, not just for MySQL.
Nice one, thanks!
Actually is’s not necessary to reboot. Just stop mysql, mount the ramdisk, start mysql again should do.
sudo service mysql stop
sudo mount /mnt/ramdisk
sudo service mysql start