Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to access MySQL and execute multiple large queries with a "here document" in a shell script.

Running the following command works perfectly fine:

/usr/bin/mysql -u username -ppassword -h localhost database

Running this command results in an Access Denied error:

/usr/bin/mysql -u username -ppassword -h localhost database << EOF
--MySQL queries here
EOF

This is the error I receive:

ERROR 1045 (28000) at line 3: Access denied for user 'username'@'localhost'

With the only difference in the two methods being the << EOF, why am I all of a sudden receiving an error?

share|improve this question

marked as duplicate by Michael Hampton Jul 19 at 5:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Could you try /usr/bin/mysql -u username -ppassword -h localhost database < file_with_sqls.txt? –  mailq Aug 3 '11 at 17:42
    
Getting the same error. I think arheops might be right in that it is something in my query that is getting denied. –  Nick Aug 3 '11 at 18:01

3 Answers 3

up vote 0 down vote accepted

You need FILE privilege to import data from file. This is probably missing for your username.

See MySQL LOAD DATA INFILE user privilege settings

share|improve this answer
    
This was the problem. I was logging in with a user that did not have the proper privileges. I switched to root and it works fine now. Thank you. –  Nick Aug 3 '11 at 18:12
ERROR 1045 (28000) at line 3

So please show us the query from line 3. Maybe you have only some permissions or have no permissions to some tables.

share|improve this answer
    
If the /usr/bin/mysql command is included as line 1, then line 3 would be Load data local infile '/home/file.csv' into table table_name1 fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';. If not, then line 3 would be a select query. –  Nick Aug 3 '11 at 17:56

For Ubuntu (12.04 tested) users is not enough granting permissions for MySQL user.

This problem is more complex and related to AppArmor MySQL LOAD DATA INFILE - AppArmor issue

share|improve this answer

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