Follow the below mentioned steps to setup MySQL temp directory on a RAM disk.
Create a tmpfs directory :
mkdir /var/tmpfs
Now change the ownership of the newly created directory.
chown mysql:mysql /var/tmpfs
id mysql
Make sure to get the uid and gid for mysql
vi /etc/fstab
tmpfs /var/tmpfs tmpfs rw,uid=498,gid=499,size=500M,nr_inodes=10k,mode=0700 0 0
Save and quit.
mount -a
vi /etc/my.cnf #or the mysql config file for your server
[mysqld]
tmpdir=/var/tmpfs
tmp_table_size=2K
Restart MySQL