服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Mysql - 解决MySQL去除密码登录告警的问题

解决MySQL去除密码登录告警的问题

2022-10-21 16:12忘川的彼岸 Mysql

这篇文章主要介绍了MySQL去除密码登录告警的问题,解决方法是使用mysql_config_editor,本文通过示例代码给大家介绍的非常详细,需要的朋友可以参考下

背景

MySQL在命令行输入密码时会提示mysql: [Warning] Using a password on the command line interface can be insecure.,在某些时候会干扰取值。

解决方法:

使用mysql_config_editor可以解决这一问题。
login-path是从MySQL5.6开始支持的特性,借助mysql_config_editor工具可以将登陆MySQL的认证信息加密存放在.mylogin.cnf文件。之后,MySQL客户端可以通过读取该加密信息进行登陆。

示例:

?
1
2
[root@localhost mysql]# mysql_config_editor set --login-path=db_admin --host=192.168.1.6 --user=root --password
Enter password:         # 输入密码

参数

?
1
2
3
4
5
6
–login-path=name 登陆信息名称
–host=name 登陆地址
–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
–user 用户名
–port=name 端口
–socket=name sock文件

查看

?
1
2
3
4
# 显示指定名称的登陆信息
mysql_config_editor print --login-path=test
# 显示所有登陆信息
mysql_config_editor print --all

示例:

?
1
2
3
4
5
6
7
8
9
10
[root@localhost mysql]# mysql_config_editor print --all
[db_admin]
user = root
password = *****
host = 192.168.1.6
[root@localhost mysql]# mysql_config_editor print --login-path=db_admin
[db_admin]
user = root
password = *****
host = 192.168.1.6

删除配置

?
1
mysql_config_editor remove --login-path=test

登陆

?
1
2
3
4
5
6
7
8
9
10
root@localhost mysql]# mysql --login-path=db_admin
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10222
Server version: 5.7.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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.
mysql>

到此这篇关于MySQL去除密码登录告警的文章就介绍到这了,更多相关MySQL密码登录告警内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/os-linux/p/16168527.html

延伸 · 阅读

精彩推荐