Why can't I pipe a password into mysql non-interactively? -


i want run mysql client, giving password non-interactively.

the standard solution this

mysql -u root -e "foo" -p < password_file 

but situation this

produce_password | mysql -u root -p 

here, mysql prompts password, though data being piped in. (yes, produce_password emitting data; echo foo | mysql behaves same way.)

the internet seems think above should work, fact doesn't. workaround be

produce_password > password_file mysql -u root -p < password_file rm password_file 

but let's don't want (e.g. policy demands password never written disk)

how can make mysql take password input process without prompting, file?

i don't know how explain this, when pipe something, stdout of first program forwarded stdin of second program. somehow confuse this, command line or whatever. can pipe mysql, of course, whatever pipe handled after you've authenticated yourself.

the solution

mysql -u root -p$(produce_password) 

this generates password whatever program have there , puts in right place on commandline (my english bad, can't explain better). when have in file do

mysql -u root -p$(cat file) 

i don't know, why want way anyway, might interested in having encrypted file credentials, can use log in without specifying password. read more here.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -