我已经创建了这样的shell脚本,但是我在grant命令中遇到了语法错误。请有人帮帮我吗?
ssh -t qbadmin@10.3.2.0 '
su root -c "
echo \"Give db name :\";
read db_name;
echo \"Give password :\";
read db_pass;
host=localhost;
sql1=\"create database \$db_name;\";
sql2=\"grant all on \${db_name}.* to \${db_name}@\${host} identified by \"\${db_pass}\";\";
sql3=\"\${sql1}\${sql2}\";
echo \"==============\";
mysql -u root -p -e \"\${sql3}\";
";
'
答案 0 :(得分:0)
我找到了解决方案。
通过在"\\\""
之前和之后放置\${db_pass}
,我解决了这个问题。 grant命令运行良好,没有任何语法错误!
感谢大家的支持。
ssh -t qbadmin@10.3.2.0 '
su root -c "
echo \"Give db name :\";
read db_name;
echo \"Give password :\";
read db_pass;
host=localhost;
sql1=\"create database \$db_name;\";
sql2=\"grant all on \${db_name}.* to \${db_name}@\${host} identified by "\\\""\${db_pass}"\\\"";\";
sql3=\"\${sql1}\${sql2}\";
echo \"==============\";
mysql -u root -p -e \"\${sql3}\";
";
'