方法一
mysql -h localhost -u user -ppassword -e “show databases”
方法二
mysql –defaults-file=/xxxx/xx/my.cnf databasename -e “select column from table”
ps: 方法一 p 和 password 之間不要有空白
方法二 defaults 前是有兩個 dash(-)
reference:
https://www.psce.com/en/blog/2012/04/01/how-to-find-mysql-configuration-file/
https://stackoverflow.com/questions/42865795/shell-script-to-connect-to-mysql-server
https://www.phpini.com/mysql/shell-script-safe-connect-mysql
[mysql]Shell Script 連接 MySQL 安全寫法
分類:mysql