我们为mysql备份或者用mysql某些自动化脚本的时候,需要将用户、密码等信息明文显示出来,任何能够看到该脚本的人都能拿到用户密码(虽说能够看到该脚本的人大部分为内部人员),这样做是些微风险。

mysql 5.6提供了mysql_config_editor加密工具,使用非常简单

# 在shell环境下
mysql_config_editor set --login-path=test_pass --host=localhost --user=root --password
Enter password: *******
# 再用mysql登录
mysql --login-path=test_pass