11

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?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
  • Is this a hosted environment? How is the SQL being invoked? If it's from a web server, the user is likely whatever the web server uses to run request handlers. – Jim Garrison Nov 22 '10 at 21:12
  • If you are using MySQL in a **docker** container, the file will be output into your docker too. – Belter Mar 21 '19 at 05:20

4 Answers4

14

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

Doon
  • 19,719
  • 3
  • 40
  • 44
  • well problem #2 is standard unix file perms issue. You can set your directory to group www-data, and give g+w perms to that directory. but that is probably not what you want to do, as that would allow any body with access to the web server to write to that directory. What are you calling this from (PHP?, PERL?). The better option is to look into suexex or suphp (I think). to make the script run as your user... – Doon Nov 22 '10 at 21:44
  • I tried countless solutions (changing AppArmor, running as root, chown, etc.) and only this worked. – eb80 Sep 04 '18 at 18:16
9

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

Navrattan Yadav
  • 221
  • 3
  • 5
0

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

Community
  • 1
  • 1
tony gil
  • 9,424
  • 6
  • 76
  • 100
0

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.

Community
  • 1
  • 1
Chris Thornton
  • 15,620
  • 5
  • 37
  • 62