0

I'm creating a script that can be deployed to multiple administrators who would be able to run it with their own credentials.

I'm getting an Access Denied error from mysql, however. It seems to think that I'm not passing a username to the MySQL command:

Using this script:

set dbUser = "myusername"
set dbPass = "mypassword"
mysql --username=$dbUser --password=$dbPass --database="mydbname" -e "SELECT * FROM sometable"

ERROR 1044 (42000): Access denied for user ''@'localhost' to database

Strangely, if I type the MySQL username and password directly into the MySQL command and run that in a shell script it works fine.

mysql --username="myusername"--password="mypass" --database="mydbname" -e "SELECT * FROM sometable"
OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
sbook
  • 841
  • 1
  • 8
  • 13

1 Answers1

0

For bash... don't you want -


dbUser=myusername
dbPass=mypassword
mysql --username=$dbUser --password=$dbPass --database="mydbname" -e "SELECT * FROM sometable"
tamarintech
  • 1,972
  • 12
  • 17
  • That's embarrassing on my part, was indeed the problem! Thanks for spotting that – sbook Mar 25 '11 at 16:51
  • it's a good idea to get in the habit of always quoting variables, unless you specifically want the side effects of omitting the quotes: `mysql --username="$dbUser" --password="$dbPass" ...` – glenn jackman Mar 25 '11 at 16:52