MySQL 5.6 Warning - Using a password on the command line interface can be insecur 解决方案

Warning: Using a password on the command line interface can be insecur

 

MySQL 5.6 版本对安全性进行了增强,如果在命令中使用了 -ppassword ,就会有告警提示:Warning: Using a password on the command line interface can be insecure;

那么问题来了,我们经常用脚本完成一些工作,例如备份、监控、检测等等,不同工作可能采用不同的MySQL用户及权限,常用方式都是采用 -uusername -ppassword 内置到脚本中,这样就会触发告警。

如何解决呢?总结了一下,可以采取如下几种方案:

方案一:将权限写到配置文件里,通过 --defaults-extra-file= 方式加载。

方案二:通过MySQL 5.6 新增命令 mysql_config_editor http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html 来预置相关权限信息

方案三:将告警信息输出到文件或丢弃,采用 2>/dev/null 2>/path/file 等方式,简单粗暴有效,但容易忽略掉其他告警信息

方案四:通过环境变量存储密码,export MYSQL_PWD=password ; mysql -uusername ,该方案简单有效,推荐之

 

标签: MySQL
评论: 0 | 引用: 0 | 阅读: 12309