0

I have created a shell script as given below.The aim is to create a database in a remote machine and give all privileges on that database for a specific user in remote machine.
The shell script is as follows.

ssh [email protected] 'echo "db name :";
read db_name;
echo "db user :";
read db_user;
echo "user password:";
read password;
host=localhost;
sql1="create database $db_name;";
sql2="grant all on ${db_name}.* to ${db_user}@${host} identified by "${password}";";
sql3="${sql1}${sql2}";
mysql -u root -p -e "${sql3}";
'

And the output Iam getting is as foloows

[email protected]'s password:
db name :
amblex
db user :
qbadmin
user password:
xxxx
Enter password: xxxx
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'qburst'
at line 1

What could be the mistake in my script.PLease help me to resolve this.

Thanks in advance.

1
  • Reference Commented Feb 28, 2013 at 4:06

1 Answer 1

0

Instead of ...

sql2="grant all on ${db_name}.* to ${db_user}@${host} identified by "${password}";";

... try this ...

sql2="grant all on ${db_name}.* to ${db_user}@${host} identified by \"${password}\";";

Also you might want to consider using expect.

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

Comments

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.