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"
1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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.
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?
this is just a piece of data I need to insert into the .sql file and execute that on the server
A plain-text file can't do that. You need some kind of script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.