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:
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.