Shell script to connect to MySQL server

2019-07-09 05:21发布

I have about 20 different MySQL instances that I'd like to easily connect to without having to input the whole address, username, and crazy long password each time. What can I do to script this process, so all I have to do is run one .sh script for each instance?

What I have so far, saved as "instance1.sh"

#!/bin/bash
mysql -h instance1-address.com -u username -p password -e "show databases"

After making this file executable, it still asks for my password, even though it is in the script itself. What can I do?

标签: mysql bash shell
1条回答
何必那么认真
2楼-- · 2019-07-09 06:26

remove the space after -p so like this:

#!/bin/bash
mysql -h instance1-address.com -u username -ppassword -e "show databases"

it will still show a warning about it being insecure

查看更多
登录 后发表回答