0

I am going to run the following, but need to pass a password into .sql file as well. I am hoping I will read pwd from the some secure file and can pass it in

mysql --login-path=db_server ${db} < "/path/to/sql_script/update.sql"
epipko
  • 397
  • 1
  • 6
  • 15
  • found an answer to my question here: https://stackoverflow.com/questions/10229324/pass-parameter-to-mysql-script-command-line – epipko Aug 24 '17 at 18:22

1 Answers1

1

Although the command-line tool will get really upset, it'll still let you supply a password with the --password=XXXXX argument. You cannot put it in the .sql file.

You can also put the password in a config file in your home directory, like .mylogin.cnf or ~/my.cnf

tadman
  • 208,517
  • 23
  • 234
  • 262
  • It's my fault for not stating requirements cleanly. I need to be able to pass a variable (in my case it will be pwd) into .sql script that is being run by mysql. In this case, update.sql contains an update statements: update T set pwd="PWD". So I'd like to be able to pass PWD value into .sql. Hope this makes sense. – epipko Aug 23 '17 at 16:58
  • It's not clear. Do you mean you want to pass in a password for *connecting to the server* or is this just a piece of data you need to insert into the .sql file and execute that on the server? – tadman Aug 23 '17 at 18:06
  • this is just a piece of data I need to insert into the .sql file and execute that on the server – epipko Aug 23 '17 at 18:26
  • A plain-text file can't do that. You need some kind of script. – tadman Aug 23 '17 at 18:30