跳转至

Mysql 使用defaults-file参数免密登录


2015-07-09 by dongnan

举个栗子

Mysql直接使用密码登录数据库时,会提示警告信息:

mysql -urep1 -pywwd.net -e "show slave status \G"
Warning: Using a password on the command line interface can be insecure.
#...省略

目标

Mysql 使用 defaults-file 参数免密码登录服务器。

操作步骤

创建 .my.cnf 文件,添加 mysql 账户信息:

cat /var/lib/zabbix/.my.conf

[client]
#for rep
host=localhost
user=rep1
password=ywwd.net
socket = /tmp/mysql.sock

文件比较重要保证最小的权限

chmod 600 .my.conf

验证

成功登录服务器

mysql --defaults-file=/var/lib/zabbix/.my.conf
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.6.25-log Source distribution
#...省略
mysql>

扩展

Mysql 主从状态监控脚本

回到页面顶部