Linux SELECT INTO OUTFILE 无法写入文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4250243/
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
SELECT INTO OUTFILE can't write to file
提问by Jason Swett
I'm trying to do a SELECT INTO OUTFILE
and I'm getting the following error:
我正在尝试执行SELECT INTO OUTFILE
,但出现以下错误:
General error: 1 Can't create/write to file '/home/jason/projects/mcif/web/downloads/dump.csv' (Errcode: 13). Failing Query: "
SELECT name
INTO OUTFILE '/home/jason/projects/mcif/web/downloads/dump.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
FROM account a
I know what the problem probably is: my downloads
folder isn't writable by my MySQL user. I don't know how to solve this problem for two reasons:
我知道问题可能是什么:downloads
我的 MySQL 用户无法写入我的文件夹。我不知道如何解决这个问题,原因有两个:
- I don't know how to find out what the MySQL user is
- I don't know how to add the MySQL user to the users who are able to write to the
downloads
folder
- 我不知道如何找出 MySQL 用户是什么
- 我不知道如何将 MySQL 用户添加到能够写入
downloads
文件夹的用户中
I'm on Ubuntu Linux. Can someone help me get past those two things?
我在 Ubuntu Linux 上。有人能帮我解决这两件事吗?
采纳答案by Doon
write the file /tmp/dump.csv and the copy it over.. That will let you see who is running what. My guess is that you are doing this from the web and the client is running as the web server process...
写入文件 /tmp/dump.csv 并将其复制过来。这会让你看到谁在运行什么。我的猜测是您是从 Web 执行此操作,并且客户端正在作为 Web 服务器进程运行...
回答by Chris Thornton
Here's a discussion that may help: How can I have MySQL write outfiles as a different user?
这是一个可能有帮助的讨论: 如何让 MySQL 以不同的用户身份写入输出文件?
Also, please try to avoid clouding your questions with fluff. In your case, you already know it's a permissions issue, so all of your SQL joins and tables don't matter. You could have simply used one field from one table in your select, to demonstrate the problem without clouding things up.
另外,请尽量避免用绒毛使您的问题蒙上阴影。在您的情况下,您已经知道这是一个权限问题,因此您的所有 SQL 联接和表都无关紧要。您可以简单地使用选择中的一张表中的一个字段来演示问题,而不会使事情变得混乱。
回答by tony gil
the client will probably be mysqld
. you must change apparmor authorizations and it will work fine. check out this answer
客户可能会mysqld
。您必须更改 apparmor 授权,它才能正常工作。看看这个答案
回答by Navrattan Yadav
mysql -u USERNAME --password=PASSWORD --database=DATABASE --execute='SELECT FIELD
, FIELD
FROM TABLE
LIMIT 0, 10000 ' -X > file.xml
mysql -u USERNAME --password=PASSWORD --database=DATABASE --execute='SELECT FIELD
, FIELD
FROM TABLE
LIMIT 0, 10000 ' -X > file.xml