I have the following shell script that relies on $HOME/.my.cnf to supply the password. The two calls to mysql are equivalent, but the second one prompts for a password whereas the first does not. I am trying to write some shell scripts with the connectivity details parameterized except for password. I tried using #!/bin/sh. There is no whitespace after any of the parameters. Any suggestions?
$ cat processlist-state.sh
#!/bin/bash
export HOSTNAME=mysql-us-east-1-123456789.abcdefghijklm.us-east-1.rds.amazonaws.com
export PORT=3306
export USERNAME=master_user
mysql -h mysql-us-east-1-123456789.abcdefghijklm.us-east-1.rds.amazonaws.com -P 3306 -u master_user -e "show processlist"
mysql -h ${HOSTNAME} -p ${PORT} -u ${USERNAME} -e "show processlist"
$ cat $HOME/.my.cnf
[client]
password=password
-p in the second call forces the password prompt.
-p = ask for password
-P = connection port
-p{PASSWORD} = use {PASSWORD} from commandline as password
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.