mysql - Bash 脚本 Mysql 警告 : Using a password on the command line interface can be insecure

标签 mysql linux bash passwords

您好,我有一个脚本可以对一些 mysql 数据库进行分区。我们正在从 5.5 升级到 5.6。在测试脚本时,我注意到新的 5.6 版本的 mysql 返回 Warning: Using a password on the command line interface can be insecure. 解决此问题的最佳方法是什么?我读到一个解决方法是 2>/dev/null 但我将无法获得退出代码或任何错误,如果它们发生的话。有没有其他方法可以做到这一点。这是有问题的代码行:

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 文件中设置适当的变量。与此类似的内容应该有所帮助:

[mysql]                                                                                                                                                   
user=my_username                                                                                                                                          
password=my_password

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

关于mysql - Bash 脚本 Mysql 警告 : Using a password on the command line interface can be insecure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23762575/

相关文章:

php - 在 PHP 中从数据库构造外部类

php - 我将如何从列中的第二行中获取 echo ?

mysql - Redmine 安装问题 rake 命令问题,MySQL 数据库问题?

linux - git否定排除 stash 文件的 stash 目录

linux 使用 watch 命令进行多次调用

python - python 中 subprocess.Popen() 打开的连接应该关闭吗

php - 如何设置从 PHP 创建文件的最低权限

linux - Bash:无法在 Linux 上启动使用 make 创建的程序

linux - 使用 sed 或替代函数提取文本行中 $ 和 < 之间的值

linux - 期望脚本自动 FTP 上传正在将损坏的文件发送到服务器