bash 用于连接 MySQL 服务器的 Shell 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42865795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Shell script to connect to MySQL server
提问by twalrus
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?
我有大约 20 个不同的 MySQL 实例,我想轻松连接到它们,而无需每次输入完整的地址、用户名和疯狂的长密码。我能做些什么来编写这个过程的脚本,所以我所要做的就是为每个实例运行一个 .sh 脚本?
What I have so far, saved as "instance1.sh"
到目前为止我所拥有的,保存为“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?
使这个文件可执行后,它仍然要求我输入密码,即使它在脚本本身中。我能做什么?
回答by Jpsh
remove the space after -p
so like this:
-p
像这样删除空格:
#!/bin/bash
mysql -h instance1-address.com -u username -ppassword -e "show databases"
it will still show a warning about it being insecure
它仍然会显示关于它不安全的警告