SELECT INTO OUTFILE can't write to file

﹥>﹥吖頭↗ 提交于 2019-11-30 03:21:40

问题


I'm trying to do a SELECT INTO OUTFILE and I'm getting the following error:

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:

  • 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

I'm on Ubuntu Linux. Can someone help me get past those two things?


回答1:


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...




回答2:


mysql -u USERNAME --password=PASSWORD --database=DATABASE --execute='SELECT FIELD, FIELD FROM TABLE LIMIT 0, 10000 ' -X > file.xml




回答3:


Here's a discussion that may help: How can I have MySQL write outfiles as a different user?

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.




回答4:


the client will probably be mysqld. you must change apparmor authorizations and it will work fine. check out this answer



来源:https://stackoverflow.com/questions/4250243/select-into-outfile-cant-write-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!