views:

21

answers:

1

I'm trying to create a csv export of data from mysql using the following query:

SELECT * INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM getfreepellets WHERE 1

And I get the following error:

#1045 - Access denied for user '[username]'@'localhost' (using password: YES)

(removed username but it's the right one)

How would I go about granting access to this user to create a file on the server?

Edit:

I changed the first line to be my exact home path, and received the same error.

+2  A: 

You may want to GRANT your user the FILE privilege:

The FILE privilege gives you permission to read and write files on the server host using the LOAD DATA INFILE and SELECT ... INTO OUTFILE statements and the LOAD_FILE() function.

A user who has the FILE privilege can read any file on the server host that is either world-readable or readable by the MySQL server. (This implies the user can read any file in any database directory, because the server can access any of those files.) The FILE privilege also enables the user to create new files in any directory where the MySQL server has write access. As a security measure, the server will not overwrite existing files.

To grant the FILE privilege, log-in as root and execute:

GRANT FILE ON *.* TO 'your_user'@'localhost';
Daniel Vassallo
I'm live chatting with tech support for my host right now. I linked them your answer. Waiting...
hookedonwinter
Apparently BlueHost is unable to grant this privilege on a shared server. FYI. But, I'm going to assume you are correct and mark this answer accepted. And time to create a php export.
hookedonwinter
hookedonwinter: Thanks for accepting. I will test it out later on, to make sure that error 1045 is in fact returned when a user does not have the FILE privilege.
Daniel Vassallo
@hookedonwinter: Just tried it out, and in fact a user without the `FILE` privilege will receive the #1045 error. Therefore that would have solved it, if the host allowed it.
Daniel Vassallo