MySQL uses the value of the tmpdir environment variable as the path name of the directory in which to store temporary files. If tmpdir is not set, MySQL uses the system default, which is usually /tmp, /var/tmp, or /usr/tmp.
In order to help improve MySQL performance the MySQL tmpdir could me stored in memory rather than on disk.
Master MySQL my.cnf:
- tmpdir = /dev/shm
The MySQL tmpdir path is used for temporary tables. These cannot always be avoided even if you increase max_heap_table_size and tmp_table_size, since BLOB and TEXT columns are not allowed in memory tables. You can see how MySQL is handling temporary tables, by examining the results of ‘SHOW GLOBAL STATUS LIKE ‘Created_tmp%’;’
Depending on your individual server performance requirements, storing the MySQL tmpdir in memory using tmpfs rather than on disk might be a useful MySQL performance enhancing option. Using ramfs or tmpfs you can allocate server memory to be used as a mount point.
- # mkdir -p /mnt/tmpfs
- # mount -t tmpfs -o size=64M tmpfs /mnt/tmpfs
- # mkdir -p /mnt/ramfs
- # mount -t ramfs -o size=64M ramfs /mnt/ramfs
Tmpfs or Ramfs
Both tmpfs and ramfs allow you to use server memory as a mount point with a few differences.
- Tmpfs will not grow dynamically – tmpfs will not allow you to write more data than the size you specified when mounting the tmpfs mount point. Tmpfs will use swap.
- Ramfs will grow dynamically – ramfs will allow you to write more data than the size you specified when mounting the ramfs mount point, potentially exhausting available memory. Ramfs does not use swap.
MySQL Master-Slave Replication
If the MySQL server is acting as a replication slave, you should not set tmpdir to point to a directory on a memory-based file system. A replication slave needs some of its temporary files to survive a machine restart so that it can replicate temporary tables or LOAD DATA INFILE operations. If files in the temporary file directory are lost when the server restarts, replication fails.
If you are using MySQL master-slave replication, it may be advisable to set the slave_load_tmpdir to a disk based directory eg /tmp on the slave server.
Slave MySQL my.cnf:
- tmpdir = /dev/shm
- slave_load_tmpdir = /tmp
4,432 total views, 5 views today