MySQL 更改mysql的tmp文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11990887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:30:30  来源:igfitidea点击:

Changing the tmp folder of mysql

mysqltmp

提问by Maxim Dsouza

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写入的临时文件夹的路径究竟如何更改?

回答by CyberDem0n

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/wantfor mysql user

PS不要忘记给/whatewer/you/wantmysql用户写权限

回答by Elijah Lynn

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(内存/ram):

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

Add:

添加:

[mysqld]
tmpdir = /run/mysqld

Then:

然后:

sudo service mysql restart

Verify:

核实:

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.htmlhttps://blogs.oracle.com/jsmyth/entry/ apparmor_and_mysql

回答by RedFilter

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.

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.

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

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

回答by sjas

if you dont have apparmor or selinux issues, but still get errorcode 13's:

如果您没有 apparmor 或 selinux 问题,但仍然收到错误代码 13:

mysql must be able to access the full path. I.e. all folders must be mysql accessible, not just the one you intend in pointing to.

mysql 必须能够访问完整路径。即所有文件夹都必须是 mysql 可访问的,而不仅仅是您打算指向的文件夹。

example, you try using this in your mysql configuration: tmp = /some/folder/on/disk

例如,您尝试在 mysql 配置中使用它: tmp = /some/folder/on/disk

# will work, as user root:
mkdir -p /some/folder/on/disk
chown -R mysql:mysql /some

# will not work, also as user root:
mkdir -p /some/folder/on/disk
chown -R mysql:mysql /some/folder/on/disk