sh script for executing mysql script with entering pass
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'd like to execute a mysql script where the 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?
command-line bash scripts database sh
add a comment |Â
up vote
1
down vote
favorite
I'd like to execute a mysql script where the 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?
command-line bash scripts database sh
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'd like to execute a mysql script where the 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?
command-line bash scripts database sh
I'd like to execute a mysql script where the 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?
command-line bash scripts database sh
command-line bash scripts database sh
edited 10 mins ago
dessert
19.9k55795
19.9k55795
asked 3 hours ago
Jocky Doe
1235
1235
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
According to the docs
mysql -u root -p --execute="SELECT User, Host FROM mysql.user"
prompts for a password, executes the given command, and returns to the shell (no logout required).
If you instead want your own prompt you need to script it:
#!/usr/bin/env bash
echo "Enter pwd"
read pwd
mysql -u root -p$pwd --execute="SELECT User, Host FROM mysql.user"
Please note that there must be no space between -p
and $pwd
because mysql
then considers $pwd
to be the database's name.
I would not recommend that because the password is then shown in
cleartext in the terminal whereas mysql -p
shows asterisks instead.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
According to the docs
mysql -u root -p --execute="SELECT User, Host FROM mysql.user"
prompts for a password, executes the given command, and returns to the shell (no logout required).
If you instead want your own prompt you need to script it:
#!/usr/bin/env bash
echo "Enter pwd"
read pwd
mysql -u root -p$pwd --execute="SELECT User, Host FROM mysql.user"
Please note that there must be no space between -p
and $pwd
because mysql
then considers $pwd
to be the database's name.
I would not recommend that because the password is then shown in
cleartext in the terminal whereas mysql -p
shows asterisks instead.
add a comment |Â
up vote
3
down vote
accepted
According to the docs
mysql -u root -p --execute="SELECT User, Host FROM mysql.user"
prompts for a password, executes the given command, and returns to the shell (no logout required).
If you instead want your own prompt you need to script it:
#!/usr/bin/env bash
echo "Enter pwd"
read pwd
mysql -u root -p$pwd --execute="SELECT User, Host FROM mysql.user"
Please note that there must be no space between -p
and $pwd
because mysql
then considers $pwd
to be the database's name.
I would not recommend that because the password is then shown in
cleartext in the terminal whereas mysql -p
shows asterisks instead.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
According to the docs
mysql -u root -p --execute="SELECT User, Host FROM mysql.user"
prompts for a password, executes the given command, and returns to the shell (no logout required).
If you instead want your own prompt you need to script it:
#!/usr/bin/env bash
echo "Enter pwd"
read pwd
mysql -u root -p$pwd --execute="SELECT User, Host FROM mysql.user"
Please note that there must be no space between -p
and $pwd
because mysql
then considers $pwd
to be the database's name.
I would not recommend that because the password is then shown in
cleartext in the terminal whereas mysql -p
shows asterisks instead.
According to the docs
mysql -u root -p --execute="SELECT User, Host FROM mysql.user"
prompts for a password, executes the given command, and returns to the shell (no logout required).
If you instead want your own prompt you need to script it:
#!/usr/bin/env bash
echo "Enter pwd"
read pwd
mysql -u root -p$pwd --execute="SELECT User, Host FROM mysql.user"
Please note that there must be no space between -p
and $pwd
because mysql
then considers $pwd
to be the database's name.
I would not recommend that because the password is then shown in
cleartext in the terminal whereas mysql -p
shows asterisks instead.
edited 9 mins ago
dessert
19.9k55795
19.9k55795
answered 2 hours ago
PerlDuck
4,00311030
4,00311030
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1077725%2fsh-script-for-executing-mysql-script-with-entering-pass%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password