MySQL5.6 Using a password on the command line interface can be insecure解决方法

原文链接:https://blog.csdn.net/wk1063645973/article/details/49562697
其实报出警告后,数据也是在导入,不妨碍
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 脚本就可以了;备份脚本中不需要涉及用户名密码相关信息;

### MySQL命令行接口中的密码安全风险 在命令行界面中直接输入MySQL密码存在显著的安全隐患。当通过命令行参数传递密码时,该密码可能会被其他用户通过进程列表查看到[^2]。 ```bash /usr/bin/mysqldump -u root -pMySecretPassword databases > ./backup.sql && echo "success" || echo "fail" ``` 上述命令会将明文形式的`MySecretPassword`暴露给任何能够访问系统的用户,这增加了未经授权访问的风险。 ### 替代方案 #### 使用配置文件保存凭证信息 一种更安全的做法是利用`.my.cnf`或类似的客户端选项文件来存储认证数据: ```ini [client] user=root password=MySecurePassphrase ``` 此方法不仅提高了安全性,还简化了日常操作流程,因为不再需要每次手动提供登录凭据。 #### 利用环境变量设置敏感信息 另一种推荐的方式是在执行脚本之前定义必要的环境变量,在实际调用mysqldump或其他工具时不显式指定账户名和口令: ```bash export MYSQL_PWD='YourStrongPasswordHere' ``` 这种方式可以有效防止密码泄露至shell历史记录以及系统活动监视器之中。 #### 实施基于SSL/TLS加密连接 对于远程数据库服务器之间的交互而言,启用传输层保护措施至关重要。确保通信链路受到良好配置的TLS协议守护可极大程度上抵御中间人攻击威胁。 ```sql GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%' REQUIRE SSL; FLUSH PRIVILEGES; ``` 以上策略共同作用下能构建起较为完善的防护体系,保障MySQL服务端与客户端间的数据交换过程始终处于受控状态之下。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值