MySQL 无法创建/写入文件“xxxx.txt”(错误代码:13 - 权限被拒绝)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20446655/
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
Can't create/write to file 'xxxx.txt' (Errcode: 13 - Permission denied)
提问by Jason
mysql> \T abc.txt
./mysql: Can't create/write to file 'abc.txt' (Errcode: 13 - Permission denied)
Error logging to file 'logPremiereQueries.txt'
I meet the same problem when I use Windows 8. I solve it by running cmd (MySQL 5.6 Command Line Client) as administrator. And then I could easily find the position of abc.txt. However, in Mac OS X, I do not know how to change the permission. And if log to file successfully, where to find this 'abc.txt'? Any ideas? Thank you very much!
我在使用 Windows 8 时遇到了同样的问题。我通过以管理员身份运行 cmd(MySQL 5.6 命令行客户端)来解决它。然后我可以很容易地找到abc.txt的位置。但是,在 Mac OS X 中,我不知道如何更改权限。如果成功登录到文件,在哪里可以找到这个“abc.txt”?有任何想法吗?非常感谢!
回答by Gerg? Czuczor
Just leaving this here for the future...
留在这里留待以后吧……
If you are using Windows, open services. Right click on mysql service, select properties. In the properties window select Log On tab then Log on as: Local System account.
如果您使用的是 Windows,请打开服务。右键单击mysql服务,选择属性。在属性窗口中选择登录选项卡,然后登录为:本地系统帐户。
If you are ready, restart the service and you can select into outfile anywhere where you have permission to write.
如果你准备好了,重启服务,你可以在任何你有写权限的地方选择到 outfile 中。
回答by Arunkumar
I have faced this problem and solved this bug.
我遇到了这个问题并解决了这个错误。
SELECT * FROM mahitab INTO OUTFILE '/var/lib/mysql-files/mahitab.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINE;
ERROR 1 (HY000): Can't create/write to file '/var/lib/mysql-files/mahitab.csv' (Errcode: 13 - Permission denied)
We have to give the permission to
我们必须允许
[root@localhost tmp]# chmod 1777 /var/lib/mysql-files/
回答by peterm
If you don't provide a specific path for a file when using tee (\T)
command mysql will try to create or append to the file in the current working directory (directory from which mysql has been started)
如果在使用tee (\T)
命令时没有为文件提供特定路径,mysql 将尝试在当前工作目录(mysql 已启动的目录)中创建或附加到该文件
The error is self explanatory - you just don't have permissions to write a file in a current working directory.
该错误是不言自明的 - 您只是无权在当前工作目录中写入文件。
If you don't know (which is strange) what is your current working directory you can execute system pwd
command from mysql command prompt
如果您不知道(这很奇怪)您当前的工作目录是什么,您可以pwd
从 mysql 命令提示符执行系统命令
mysql> \! pwd
Now to resolve the problem either:
现在要解决问题:
change your working directory in terminal to the one that you have write permissions on (e.g. your home directory) and then start mysql client
$ cd ~ $ mysql -uusername -p dbname
in mysql prompt when using
tee (\T)
command specify a valid path to the directory that you have write permissions on e.g.mysql> \T /Users/username/abc.txt
将终端中的工作目录更改为您具有写入权限的目录(例如您的主目录),然后启动 mysql 客户端
$ cd ~ $ mysql -uusername -p dbname
在使用
tee (\T)
命令时在 mysql 提示符下指定一个有效的目录路径,您对例如具有写权限的目录mysql> \T /Users/username/abc.txt
回答by user3401459
please to see -> https://dev.mysql.com/doc/refman/5.0/en/cannot-create.html
请看 -> https://dev.mysql.com/doc/refman/5.0/en/cannot-create.html
One fix is to start mysqld with the --tmpdir option or to add the option to the [mysqld] section of your option file. For example, to specify a directory of C:\temp
一种解决方法是使用 --tmpdir 选项启动 mysqld 或将该选项添加到选项文件的 [mysqld] 部分。例如,指定一个目录 C:\temp