0

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?

Nick
  • 315
  • 2
  • 7
  • 15
  • Could you try `/usr/bin/mysql -u username -ppassword -h localhost database < file_with_sqls.txt`? – mailq Aug 03 '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 03 '11 at 18:01

3 Answers3

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

mailq
  • 16,882
  • 2
  • 36
  • 66
arheops
  • 708
  • 1
  • 5
  • 13
  • 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 03 '11 at 17:56
0

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

See MySQL LOAD DATA INFILE user privilege settings

mailq
  • 16,882
  • 2
  • 36
  • 66
  • 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 03 '11 at 18:12
0

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