Bash脚本Mysql警告:在命令行界面上使用密码可能不安全 [英] Bash Script Mysql Warning: Using a password on the command line interface can be insecure

查看:328
本文介绍了Bash脚本Mysql警告:在命令行界面上使用密码可能不安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本来对一些mysql数据库进行分区.我们从5.5升级到5.6.在测试脚本时,我注意到使用新的5.6版本的mysql会返回警告:在命令行界面上使用密码可能是不安全的.修复此问题的最佳方法是什么?我读到的解决方法是 2>/dev/null ,但是如果出现错误,我将无法获取退出代码或任何错误.还有其他方法可以做到这一点.这是有问题的代码行:

Hi I have a script to partition some mysql databases. We are upgrading from 5.5 to 5.6. While testing the scripts i noticed that with the new 5.6 version mysql returns Warning: Using a password on the command line interface can be insecure. what is the best way to fix this? I read a workaround would be 2>/dev/null but I wont be able to get the exit code or any errors if they happen. Is there any other way to do this. Here is the problematic line of code:

MYSQL_RESULT=`echo "SET sql_log_bin=0;SET @pdb='$DB',@ptable='$table';CALL maintenance(@pdb,@ptable);SET sql_log_bin=1;"|mysql -uUSER -pPASSWORD database`

推荐答案

一种解决方法是在〜/.my.cnf 文件中设置适当的变量.与此类似的方法应该有所帮助:

One way to get around this is to set the appropriate variables in your ~/.my.cnf file. Something similar to this should help:

[mysql]                                                                                                                                                   
user=my_username                                                                                                                                          
password=my_password

它应该位于执行命令的用户的主目录中.并且不要忘记在文件上设置正确的权限,以免其他用户读取该文件: chmod 600〜/.my.cnf .

This should live in the home directory of the user executing the command. And don't forget to set the right permissions on the file to avoid it being readable by other users: chmod 600 ~/.my.cnf.

这篇关于Bash脚本Mysql警告:在命令行界面上使用密码可能不安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆