Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

SELECT * INTO OUTFILE '/tmp/result.csv'
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?


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

share|improve this question
up vote 2 down vote accepted

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

share|improve this answer
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
#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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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