linux 在ssh返回拒绝访问后调用mysql的Bash脚本

uqjltbpv  于 2022-11-28  发布在  Linux
关注(0)|答案(1)|浏览(113)

I am having a little trouble with a bash script im writing, i can run the individual commands in terminal and it works just fine, but running from a bash script is returning the error;

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)

The bash script is as follows;

#!/bin/bash
ssh user@myhost.com << EOF
    /usr/bin/mysql -h localhost -u root -p_kHaTX(!G_$=Y5Xa
    show databases;
EOF

I have tried to also wrap the password in '' like so

/usr/bin/mysql -h localhost -u root -p'_kHaTX(!G_$=Y5Xa'

and still nothing
But if I run the commands myself through the terminal, it all works just fine
Any help would be greatly appreciated.
Thanks

ycggw6v2

ycggw6v21#

To resolve the error, and for security purposes also, store the password in a separate file, let's say:

echo '_kHaTX(!G_$=Y5Xa' > /root/mysql_pwd

Then pass the password as variable:

MYSQL_PWD=`cat /root/mysql_pwd` /usr/bin/mysql -u root -p -e "show databases"

相关问题