更改mysql的tmp文件夹

时间:2022-09-16 10:08:39

Our Mysql queries use temporary tables which creates temporary files in the process. Currently the files are written to /tmp. How exactly can the path of the temp folder to which mysql writes to be changed?

我们的Mysql查询使用临时表,在进程中创建临时文件。目前,文件被写入/ tmp。 mysql写入的临时文件夹的路径到底怎么改变?

3 个解决方案

#1


4  

This is answered in the documentation:

这在文档中得到了解答:

Where MySQL Stores Temporary Files

MySQL存储临时文件的位置

On Unix, 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.

在Unix上,MySQL使用TMPDIR环境变量的值作为存储临时文件的目录的路径名。如果未设置TMPDIR,MySQL将使用系统默认值,通常为/ tmp,/ var / tmp或/ usr / tmp。

On Windows, Netware and OS2, MySQL checks in order the values of the TMPDIR, TEMP, and TMP environment variables. For the first one found to be set, MySQL uses it and does not check those remaining. If none of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system default, which is usually C:\windows\temp.

在Windows,Netware和OS2上,MySQL按顺序检查TMPDIR,TEMP和TMP环境变量的值。对于第一个发现设置,MySQL使用它并不检查剩余的。如果没有设置TMPDIR,TEMP或TMP,则MySQL使用Windows系统默认值,通常为C:\ windows \ temp。

#2


35  

You should edit your my.cnf

你应该编辑你的my.cnf

tmpdir = /whatewer/you/want

and after that restart mysql

然后重启mysql

P.S. Don't forget give write permissions to /whatewer/you/want for mysql user

附:不要忘记为/ whatewer / you / want for mysql用户提供写权限

#3


26  

Here is an example to move the mysqld tmpdir from /tmp to /run/mysqld which already exists on Ubuntu 13.04 and is a tmpfs (memory/ram):

这是一个将mysqld tmpdir从/ tmp移动到/ run / mysqld的示例,它已经存在于Ubuntu 13.04上并且是tmpfs(memory / ram):

sudo vim /etc/mysql/conf.d/local.cnf

Add:

加:

[mysqld]
tmpdir = /run/mysqld

Then:

然后:

sudo service mysql restart

Last:

持续:

SHOW VARIABLES LIKE 'tmpdir';

==================================================================

================================================== ================

If you get an error on MySQL restart, you may have AppArmor enabled:

如果MySQL重启时出错,您可能启用了AppArmor:

sudo vim /etc/apparmor.d/local/usr.sbin.mysqld

Add:

加:

# Site-specific additions and overrides for usr.sbin.mysqld.
# For more details, please see /etc/apparmor.d/local/README.
/run/mysqld/ r,
/run/mysqld/** rwk,

Then:

然后:

sudo service apparmor reload 

sources: http://2bits.com/articles/reduce-your-servers-resource-usage-moving-mysql-temporary-directory-ram-disk.html, https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql

来源:http://2bits.com/articles/reduce-your-servers-resource-usage-moving-mysql-temporary-directory-ram-disk.html,https://blogs.oracle.com/jsmyth/entry/ apparmor_and_mysql

#1


4  

This is answered in the documentation:

这在文档中得到了解答:

Where MySQL Stores Temporary Files

MySQL存储临时文件的位置

On Unix, 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.

在Unix上,MySQL使用TMPDIR环境变量的值作为存储临时文件的目录的路径名。如果未设置TMPDIR,MySQL将使用系统默认值,通常为/ tmp,/ var / tmp或/ usr / tmp。

On Windows, Netware and OS2, MySQL checks in order the values of the TMPDIR, TEMP, and TMP environment variables. For the first one found to be set, MySQL uses it and does not check those remaining. If none of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system default, which is usually C:\windows\temp.

在Windows,Netware和OS2上,MySQL按顺序检查TMPDIR,TEMP和TMP环境变量的值。对于第一个发现设置,MySQL使用它并不检查剩余的。如果没有设置TMPDIR,TEMP或TMP,则MySQL使用Windows系统默认值,通常为C:\ windows \ temp。

#2


35  

You should edit your my.cnf

你应该编辑你的my.cnf

tmpdir = /whatewer/you/want

and after that restart mysql

然后重启mysql

P.S. Don't forget give write permissions to /whatewer/you/want for mysql user

附:不要忘记为/ whatewer / you / want for mysql用户提供写权限

#3


26  

Here is an example to move the mysqld tmpdir from /tmp to /run/mysqld which already exists on Ubuntu 13.04 and is a tmpfs (memory/ram):

这是一个将mysqld tmpdir从/ tmp移动到/ run / mysqld的示例,它已经存在于Ubuntu 13.04上并且是tmpfs(memory / ram):

sudo vim /etc/mysql/conf.d/local.cnf

Add:

加:

[mysqld]
tmpdir = /run/mysqld

Then:

然后:

sudo service mysql restart

Last:

持续:

SHOW VARIABLES LIKE 'tmpdir';

==================================================================

================================================== ================

If you get an error on MySQL restart, you may have AppArmor enabled:

如果MySQL重启时出错,您可能启用了AppArmor:

sudo vim /etc/apparmor.d/local/usr.sbin.mysqld

Add:

加:

# Site-specific additions and overrides for usr.sbin.mysqld.
# For more details, please see /etc/apparmor.d/local/README.
/run/mysqld/ r,
/run/mysqld/** rwk,

Then:

然后:

sudo service apparmor reload 

sources: http://2bits.com/articles/reduce-your-servers-resource-usage-moving-mysql-temporary-directory-ram-disk.html, https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql

来源:http://2bits.com/articles/reduce-your-servers-resource-usage-moving-mysql-temporary-directory-ram-disk.html,https://blogs.oracle.com/jsmyth/entry/ apparmor_and_mysql