If you are on Ubuntu, then do this first:
vim /etc/apparmor.d/usr.sbin.mysqld
Add a line:
/run/mysqld/tmp/** rwk,
Restart Apparmor
service apparmor restart
Also create tmp directory and fix ownership/permissions.
mkdir /run/mysqld/tmp/
chown -R mysql:mysql /run/mysqld/tmp/
chmod 1777 /run/mysqld/tmp/
Edit mysql config
Open my.cnf
file
vim /etc/mysql/my.cnf
Set/Change tmpdir location
tmpdir = /run/mysqld/tmp
Restart Mysql
service mysql restart