用于连接到MySQL服务器的Shell脚本 [英] Shell script to connect to MySQL server
问题描述
我想轻松连接到大约20个不同的MySQL实例,而不必每次都输入完整的地址,用户名和疯狂的长密码.我该怎么做才能编写此过程的脚本,所以我要做的就是为每个实例运行一个.sh脚本?
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?
到目前为止,我保存为"instance1.sh"的
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?
推荐答案
删除-p
后的空格,如下所示:
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
这篇关于用于连接到MySQL服务器的Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!