MySQL tmpdir on /dev/shm

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.

Using tmpfs:

mkdir -p /mnt/tmpfs

mount -t tmpfs -o size=64M tmpfs /mnt/tmpfs

Using ramfs:

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

http://openquery.com/blog/experiment-mysql-tmpdir-on-tmpfs

http://openquery.com/blog/update-mysql-tmpdir-tmpfs

http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/

http://dev.mysql.com/doc/refman/5.0/en/temporary-files.html

转载于:https://my.oschina.net/panzhc/blog/178008

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值