2

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

first you must define what your database is with:

use database_name;

Then you can run your query.

If that still not working it is because you create those but you havent defined access to it for that given user.

GRANT ALL ON database_name.* TO 'someuser'@'somehost';

You can read more about the Grant usage at http://dev.mysql.com/doc/refman/5.1/en/grant.html

  • Thanks. Turns out BlueHost can't grant permissions to do this. Sadly. – PJ. Aug 7 '10 at 18:34
  • Well you can do it yourself from the cPanel under database menu, First you create a database with it then you assign a user to it, further in you can use the wizard from the database to run all steps needed. That's ofc if you have access to the cpanel within your hosting plan. – Prix Aug 7 '10 at 18:44
1
#1045 - Access denied for user '[username]'@'localhost' (using password: YES)

That error has nothing to do with file or directory permissions. That's MySQL telling you that the MySQL logon credentials you used are incorrect for that query. This may be because, as Prix pointed out, you haven't specified the database to use.

0

I spent hours trying to understand the suggestions on this page and many other pages of StackOverflow.

No matter how I changed the permissions in MySql, I couldn't get anything to work.

I reverted back to the permissions I started with.

Ultimately what worked for me was simpler than others' suggestions:

echo "select id, emailAddress FROM contacts" | mysql --user=myusername --password mydatabasename > /home/my_output_file.tsv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.