mysql: [Warning] Using a password on the command line interface can be insecure.

来自TMySQL用户,包括很多开发和GCS系统,都习惯mysql –u$USER –p$PASSWD 来执行,这条命令在MySQL 5.6会有个warning告警:

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

单据或者脚本解析到这个warning,则全部失败。

所以,为了向前兼容,我们在源码层面将这个warn关闭。


今天老左有在帮一个网友搬家网站过程中,习惯导出MySQL数据库的时候采用mysqldump命令,但是意外发生了出现"Warning: Using a password on the command line interface can be insecure."的错误提示,当然数据库肯定也没有能备份下来。这个问题应该是在MySQL5.6+版本的时候就有出现,可能是为了确保数据库的安全性采用的保护机制。

遇到问题那就去解决问题,大概搜索到国内的一些网站,大部分都是复制的,也没有讲的明白,于是还是找老外的信息,于是老左就整理到下面比较全的方法且经过验证是没有问题的。

第一种方法、修改数据库配置文件

1、我们需要修改数据库配置文件,这个要看我们数据库的配置的,有些是在/etc/my.cnf,有些是/etc/my.conf

我们需要在[client]部分添加脚本:

host=localhost
user=数据库用户
password='数据库密码'

这里参数要修改成我们自己的。

2、采用命令导出和导入数据库

其实在这个时候,我们如果采用"详解使用mysqldump命令备份还原MySQL数据用法整理"介绍的方法也是可以使用的,虽然依旧有错误提示,但是数据库还是可以导出的。您肯定和老左一样是追求细节的人,一点点问题都不能有,但我们可以用下面的命令导出和导入,就没有错误提示。

#导出数据库

mysqldump --defaults-extra-file=/etc/my.cnf database > database.sql

#导入数据库

mysql --defaults-extra-file=/etc/my.cnf database < database.sql

这里我们可以看到上面的命令和以前常用的快速导入和导入命令有所不同了,需要加载我们配置的MYSQL配置文件,这个红色部分要根据我们实际的路径修改。用这样的命令导出备份和导入是没有错误提示的。

第二种方法、利用mysql_config_editor

1、设置加密模式

mysql_config_editor set --login-path=local --host=localhost --user=db_user --password

红色部分是需要修改成我们自己数据库用户名的,回车之后会提示我们输入数据库密码,我们照样输入。

2、执行备份

mysqldump -u db_user -pInsecurePassword my_database | gzip > backup.tar.gz

根据我们数据信息修改用户和用户名和数据库密码,执行备份,这里老左测试还是有错误提示,但数据库是可以备份的。

总之,我们只要实现结果,可以选择以上2种方法其一操作,当然老左也有看到其他的方法,这里就不多分享了,如果有兴趣的可以搜索其他解决方法。



1.最近把MySQL从5.5升到5.6以后,mysqldump居然不好用了,提示:

代码如下

复制代码

[root@qttc ~]# /usr/local/mysql/bin/mysqldump  -uroot -proot db > bak.sql
Warning: Using a password on the command line interface can be insecure.

翻译过来是:在命令行界面上使用密码可以是不安全的;

这让人有点郁闷,5.5用的1直都很爽,到5.6居然说命令行方式写密码不安全?那密码写哪呢?

在官网文档找到了缘由,大家可以点击这里看看:

1.官方网址:http://dev.mysql.com/doc/refman/5.1/en/password-security-user.html

MySQL users shoulduse the following guidelines to keep passwords secure.

When you run a client program to connect to the MySQL server, it is inadvisableto specify your password in a way that exposes it to discovery by other users.The methods you can use to specify your password when you run client programsare listed here, along with an assessment of the risks of each method. Inshort, the safest methods are to have the client program prompt for thepassword or to specify the password in a properly protected option file.

翻译过来大意是在命令行下如果要使用密码可以在执行命令后的提示输入里输入密码,或者在指定的安全文件内指定密码;那安全文件时哪个呢?文档对此给出了答案:

Store your passwordin an option file. For example, on Unix, you can list your password in the[client] section of the .my.cnf file in your home directory:

可以在my.cnf内指定,于是打开我的my.cnf,在[mysqldump]下增加:

代码如下

复制代码

user=root
password=root

文中说的在[client]下面加也可以,但那样就所有块的操作都能共享了,所以生产环境上为了安全还是尽量分开;保存退出再dump就ok了;

代码如下

复制代码

[root@qttc ~]# /usr/local/mysql/bin/mysqldump db > bak.sql
[root@qttc ~]#

MySQL 5.6 警告信息 command line interface can be insecure 修复

在命令行输入密码,就会提示这些安全警告信息;

Warning: Using apassword on the command line interface can be insecure.

注:mysql -u root -pPASSWORD 或 mysqldump -u root -pPASSWORD 都会输出这样的警告信息.

1.针对mysql:

mysql -u root -pPASSWORD改成mysql -u root -p 在输入密码即可.

2.mysqldump就比较麻烦了,通常都写在scripts脚本中;

解决方法:

对于mysqldump 要如何避免出现(Warning:Using a password on the command line interface can be insecure.) 警告信息呢?

vim /etc/mysql/my.cnf

[mysqldump]

user=your_backup_user_name

password=your_backup_password

修改完配置文件后, 只需要执行mysqldump 脚本就可以了;备份脚本中不需要涉及用户名密码相关信息;



About Me

.............................................................................................................................................

● 本文整理自网络

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、博客园(http://www.cnblogs.com/lhrbest)和个人微信公众号(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文博客园地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、个人简介及小麦苗云盘地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 数据库笔试面试题库及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA宝典今日头条号地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群号:230161599(满)、618766405

● 微信群:可加我微信,我拉大家进群,非诚勿扰

● 联系我请加QQ好友(646634621),注明添加缘由

● 于 2017-08-01 09:00 ~ 2017-08-31 22:00 在魔都完成

● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

.............................................................................................................................................

● 小麦苗的微店:https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

● 小麦苗出版的数据库类丛书:http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客户端扫描下面的二维码来关注小麦苗的微信公众号(xiaomaimiaolhr)及QQ群(DBA宝典),学习最实用的数据库技术。

小麦苗的微信公众号      小麦苗的DBA宝典QQ群1     小麦苗的DBA宝典QQ群2        小麦苗的微店

.............................................................................................................................................

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26736162/viewspace-2144047/,如需转载,请注明出处,否则将追究法律责任。

[Warning] Using a password on the command line interface can be insecure.相关推荐

  1. mysql备份时过滤掉某些库 以及 去掉Warning: Using a password on the command line interface can be insecure.提示信息...

    在对mysql进行完整备份时使用--all-database参数 # mysqldump -u root -h localhost -p --all-database > /root/all.s ...

  2. 已解决:mysql: [Warning] Using a password on the command line interface can be insecure.

    在执行命令时候报错 mysql: [Warning] Using a password on the command line interface can be insecure. 解决 将密码改为后 ...

  3. 登录mysql时遇到了:mysql: [Warning] Using a password on the command line interface can be insecure.

    登录mysql时遇到了:mysql: [Warning] Using a password on the command line interface can be insecure. 问题: [ro ...

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

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

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

    1.在使用mysql命令的时候,出现问题: https://www.cndba.cn/hbhe0316/article/22635 https://www.cndba.cn/hbhe0316/arti ...

  6. mysql: [Warning] Using a password on the command line interface can be insecure.(using password:YES)

    前段时间不知道什么原因在Linux终端中出现无法启动Mysql的情况,在Linux终端中输入 mysql -uroot -p密码 的时候出现了下面这个错误: mysql: [Warning] Usin ...

  7. 去掉Warning: Using a password on the command line interface can be insecure.

    MySQL5.6之后的版本在通过客户端连接或者备份时时都会有出现如下的一个警告: Warning: Using a password on the command line interface can ...

  8. shell脚本中执行mysql 语句,去除warning using a password on the command line interface can be insecure信息...

    方法二:使用mysql参数的方法 mysql -u$user -p$pass -D $db -e "select host from user;" 当然,可以通过将传参的方式来传递 ...

  9. Warning: Using a password on the command line interface can be insecure.解决办法

    被一个小朋友问到,直接公布答案: If your MySQL client/server version is a 5.6.x a way to avoid the WARNING message a ...

最新文章

  1. HBase shell 命令执行
  2. open in browser
  3. paddle 进行目标检测_猫狗猴的识别
  4. JavaScript垃圾收集-标记清除和引用计数
  5. mysql 分库分表 ~ ShardingSphere生态圈
  6. matlab 无线仿真教学视频教程,视频教程 | MATLAB 及机电系统仿真
  7. Ruby + Passenger 5 分钟 入门
  8. 成功在开发板运行vsftpd
  9. 关于蓝牙打印机的一些问题
  10. jar启动方式设置内存参数
  11. 如何在计算机上增加一个磁盘分区,win10系统额外新增加一个硬盘分区的详细办法...
  12. Axure 9 实战案例,动态面板的应用 5,官网首页自动轮播广告
  13. 【软件工具】Anaconda使用总结
  14. ubuntu安装wine和QQ微信
  15. Python3中省略号(...)用法介绍
  16. php开发模拟基金定投网站
  17. 【网络教程】同花顺公式编辑的基本语法,帮助说明
  18. 使用C#调用GMap相关组件的基本步骤
  19. pr视频两边模糊_视频两边的这个虚化是怎么做出来的?
  20. VirtuaNES.v0.97源码探究1 多语言菜单的实现

热门文章

  1. ccurately Say CocaCola!
  2. Andriod/iOS多渠道app数据统计工具
  3. Linux 3.进程间通信(IPC)(pipe 无名管道、mkfifo 有名管道、ftok、msgget、msgrcv、msgsnd、msgctl 消息队列)
  4. 帆软FCRP认证分享
  5. maven springboot 除去指定的jar包_Spring Boot打包瘦身 Docker 使用全过程 动态配置、日志记录配置...
  6. lisp语言与python_又要头秃?2020 年七大 AI 编程语言大盘点
  7. L1-051 打折 (5 分)
  8. 可燃气体浓度多少合格_可燃气体报警器,可燃气体报警值设定为多少 - 万安迪...
  9. 红米3s进不了recovery_红米3s卡刷教程_红米3s用recovery刷第三方系统包
  10. React自定义组件使用onClick传参注意:onClick只是一个名字而已!