There are two things you can do to reduce the impact of this.
OPTION # 1: Increase tmp_table_size and / or max_heap_table_size variables
These options will determine how large the temporary table in memory is before it is considered too large, and then the pages on disk as a temporary MyISAM table. The higher these values, the less likely you will get a "copy to tmp table on disk". Please make sure that there is enough RAM on your server and max_connections is moderately configured if a single connection to the database requires a lot of RAM for its own temporary tables.
OPTION # 2: use a RAM disk for tmp tables
You should be able to configure the RAM disk in Linux, and then install tmpdir in mysql to be the folder with the RAM disk installed.
First, configure the RAM disk in the OS
Create a folder in Linux called / var / tmpfs
mkdir /var/tmpfs
Then add this line to / etc / fstab (for example, if you want to have a 16 gigabyte RAM disk)
none /var/tmpfs tmpfs defaults,size=16g 1 2
and reboot the server.
Note. You can make a RAM disk without rebooting. Just remember to add the above line to / etc / fstab to have a RAM disk after server reboot.
Now for MySQL:
Add this line to /etc/my.cnf
[mysqld] tmpdir=/var/tmpfs
and restart mysql.
OPTION # 3: Get the tmp table to the ASAP RAM disk (assuming you first use OPTION # 2)
You might want to force the tmp tables to the RAM disk as quickly as possible so that MySQL does not spin its wheels by transferring large TMP tables in memory to the RAM disk. Just add this to /etc/my.cnf:
[mysqld] tmpdir=/var/tmpfs tmp_table_size=2K
and restart mysql. This will cause even the smallest tempo table to appear on the RAM disk. You can run ls -l /var/tmpfs periodically to monitor the pace of the table.
Give it a try !!!
CAVEAT
If you see only temp tables in / var / tmpfs 24/7, this can affect the functionality / performance of the OS. To verify that / var / tmpfs is not crowded, examine your query settings. Once you do this, you will see fewer tmp tables added to / var / tmpfs.