1

I'd like to execute a mysql script where user is asked to enter the password dynamically from the command line. If possible with a message Enter your $root password However it doesn't work as expected so far I have

mysql -u root -p CREATE DATABASE IF NOT EXISTS Test

moreover when the db is created how to logout from mysql and go back to bash commands?

closed as off-topic by Thomas, roaima, user88036, Jeff Schaller, Archemar Sep 23 '18 at 16:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Thomas, roaima, Community, Jeff Schaller, Archemar

  • Also posted on askubuntu.com: askubuntu.com/questions/1077725/… – Thomas Sep 23 '18 at 13:09
  • Hello Jocky Doe. Your question is currently likely to get closed because it's been posted on two different StackExchange websites. Please choose one, and delete the other question. (Or wait, and it'll probably get closed here anyway.) – roaima Sep 23 '18 at 13:26
  • The AU one has an accepted Answer, so I suspect the U&L one should be closed. – Jeff Schaller Sep 23 '18 at 14:56
3

Use

echo "CREATE DATABASE IF NOT EXISTS Test" | mysql -u root -p

It will prompt for the password, execute the command, and return to the shell.

Not the answer you're looking for? Browse other questions tagged or ask your own question.