Linux ssh返回拒绝访问后调用mysql的Bash脚本
我在编写bash脚本时遇到了一点问题,我可以在终端中运行各个命令,它工作得很好,但是从bash脚本运行会返回错误Linux ssh返回拒绝访问后调用mysql的Bash脚本,linux,bash,stdin,heredoc,Linux,Bash,Stdin,Heredoc,我在编写bash脚本时遇到了一点问题,我可以在终端中运行各个命令,它工作得很好,但是从bash脚本运行会返回错误 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) bash脚本如下所示 #!/bin/bash ssh
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
bash脚本如下所示
#!/bin/bash
ssh user@myhost.com << EOF
/usr/bin/mysql -h localhost -u root -p_kHaTX(!G_$=Y5Xa
show databases;
EOF
还是什么都没有
但如果我自己通过终端运行命令,一切都会正常工作
任何帮助都将不胜感激
感谢解决此错误,同时出于安全目的,请将密码存储在单独的文件中,例如:
# echo '_kHaTX(!G_$=Y5Xa' > /root/mysql_pwd
然后将密码作为变量传递:
# MYSQL_PWD=`cat /root/mysql_pwd` /usr/bin/mysql -u root -p -e "show databases"
这可能有帮助:这也可能有帮助:
echo“显示数据库;”/usr/bin/mysql-h localhost-u root'-p_kHaTX(!G_$=Y5Xa'
@Cyrus…仍然返回相同的错误使用此命令测试:mysql-u root-h 127.0.0.1--password=YOUR_PASS@JJJ如果在终端中运行该命令,则找不到-bash:!:事件,如果从脚本中运行该命令,则会在意外标记“(”附近出现-bash:line 1:语法错误
# MYSQL_PWD=`cat /root/mysql_pwd` /usr/bin/mysql -u root -p -e "show databases"