解决mysql连接输入密码提示Warning: Using a password on the command line interface can be insecure...

本文介绍如何使用mysql_config_editor工具安全地管理MySQL登录信息,避免在命令行直接输入密码带来的安全隐患,并提供了具体的配置命令示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有时候客户端连接mysql需要指定密码时(如用zabbix监控mysql)5.6后数据库会给出个警告信息
mysql -uroot -pxxxx
Warning: Using a password on the command line interface can be insecure.

但是在zabbix里监控就不好取值了,除了在my.cnf中加入,但这样需要重启数据库而且也暴露了数据库密码
[mysqladmin]
user=zabbix
password=xxxxxx
[mysql]
user=zabbix
password=xxxxxx

使用mysql_config_editor可以实现将密码保存在一个配置中,下次登录不用输入用户名密码
login-path是MySQL5.6开始支持的新特性。通过借助mysql_config_editor工具将登陆MySQL服务的认证信息加密保存在.mylogin.cnf文件(默认位于用户主目录) 。之后,MySQL客户端工具可通过读取该加密文件连接MySQL,避免重复输入登录信息,避免敏感信息暴露

mysql_config_editor set --login-path=local --host=localhost --user=root --password
Enter password: (输入密码)

–login-path=name 在登录文件中为login path添加名字
–host=name 添加host到登陆文件中
–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
–user 添加用户名到登陆文件中
–port=name 添加登陆端口到登陆文件中
–socket=name 添加sock文件路径到登陆文件中

显示配置:
mysql_config_editor print --login-path=test #显示执行的login-path配置
mysql_config_editor print --all             #显示所有的login-path信息

[root@localhost ~]# mysql_config_editor print --all      
[local]
user = root
password = *****
host = localhost


删除配置:
mysql_config_editor remove --login-path=test


使用login-path登录:
[root@localhost ~]# mysql --login-path=local
Warning: Using unique option prefix sock instead of socket is deprecated and will be removed in a future release. Please use the full name instead.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.6.32-78.1-log Source distribution

Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

[root@localhost][(none)]> 

 

转载于:https://www.cnblogs.com/shansongxian/p/6893270.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值