错误重现:

命令行或者shell脚本中执行以下命令,如果您当前服务器mysql版本是大于5.6的,则会出现警告:Warning: Using a password on the command line interface can be insecure. 这是mysql避免明文密码出现在脚本中做的安全提升

mysqldump -h$1 -u$2 -p$3 -P3306 -B ${dbnames} --single-transaction --triggers --routines --events --master-data=2 -F | gzip > $data_dir/$1_`date +%Y%m%d`.sql.gz

警告信息看着不爽,特别是crontab定时执行shell时,邮件会收到“原本该忽视”的stderr标准错误。

解决方案:

这里只说一个,利用 mysql_config_editor 进行预先设置连接信息,具体做法如下:

1、设置登录信息

mysql_config_editor set --login-path=mall --host=mall.palcent.com --user=dumper -p

设置完毕,会在用户主目录%home%下生成一个.mylogin.cnf 文件,比如root用户,则生成 /root/.mylogin.cnf 。

2、查看当前主机上的加密文件

mysql_config_editor print --all

mysql: "Warning: Using a password on the command line interface can be insecure." 解决方法

3、使用加密文件

登录Mysql

mysql --login-path=mall
# Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 375021

备份数据库

mysqldump --login-path=mall --databases ${dbnames} --single-transaction --triggers --routines --events --master-data=2 -F | gzip > $data_dir/$1_`date +%Y%m%d`.sql.gz

 

当然还有其他解决方案, 请自行参考以下参考链接!

 

参考链接:

https://www.cnblogs.com/rockbes/p/3972763.html (mysql_config_editor 用法)

https://blog.csdn.net/zxssoft/article/details/89667874 

https://dev.mysql.com/doc/refman/8.0/en/password-security-user.html (官方解决方案)

 

相关文章:

  • 2021-12-30
  • 2021-08-19
  • 2021-09-20
  • 2021-07-27
  • 2022-12-23
  • 2022-02-24
  • 2021-10-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-07
  • 2022-02-20
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
相关资源
相似解决方案