mysql数据库管理-客户端快捷登陆 --login-path特性

目录

脚本测试

login-path说明

2. 配置 login-path

2.2.配置:

2.3.显示配置:

2.3.1.显示执行的login-path配置

2.3.2.显示所有的login-path信息

2.4.删除配置:

2.5.重置配置:

2.6.使用login-path登录:

2.6.1.登录host1:poet1上的MySQL

2.6.2.登录host1:poet1上的MySQL中的test_db库

3.参考:

4.实际配置命令

5.登陆效果


login-path说明

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

  • mysql 的 client 工具都能使用 login-path,如 mysql、mysqldump、mysqladmin、mysqlbinlog、mysql_upgrade、mysqld_safe、mysqld_multi、mysqldumpslow 等等。

在控制台连接数据库,需要每次输入账号密码,感觉很麻烦,偶然发现可以通过login-path保存信息,实现快捷登录,这里记录下。

  1. 配置保存账号信息

mysql_config_editor set --login-path=user1 --user=host --port=3306 -p

点击回车,会要求输入密码,这里的密码会被加密保存。

  1. 查看配置的数据库快捷登陆账号列表

C:\Users\Administrator>mysql_config_editor print --all
[client]
[test]
user = "root"
password = *****
[user1]
user = "host"
password = *****
port = 3306

  1. 删除配置

mysql_config_editor remove --login-path=test

  1. 登陆数据库

mysql --login-path=test

脚本测试

C:\Users\Administrator>mysql_config_editor set --login-path=test --user=root --host=127.0.0.1 --port=3306 -p
Enter password: ***

C:\Users\Administrator>mysql_config_editor print --all
[test]
user = "root"
password = *****
host = "127.0.0.1"
port = 3306

C:\Users\Administrator>mysql --login-path=test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.24 MySQL Community Server - GPL

Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>​​​​​​​

2. 配置 login-path

mysql_config_editor使用帮助:

mysql_config_editor set --help

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
host                              (No default value)
login-path                        client
user                              (No default value)
socket                            (No default value)
port                              (No default value)
warn                              TRUE

2.2.配置:

mysql_config_editor set --login-path=test --user=test_user  --host=127.0.0.1 --port=3306 -p

  • 其中可配置项
    • -h,–host=name 添加host到登陆文件中
    • -G,–login-path=name 在登录文件中为login path添加名字(默认为client)
    • -p,–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
    • -u,–user 添加用户名到登陆文件中
    • -S,–socket=name 添加sock文件路径到登陆文件中
    • -P,–port=name 添加登陆端口到登陆文件中

2.3.显示配置:

2.3.1.显示执行的login-path配置

mysql_config_editor print --login-path=test 

C:\Users\Administrator>mysql_config_editor print --login-path=user1
[user1]
user = "host"
password = *****
port = 3306

2.3.2.显示所有的login-path信息

mysql_config_editor print --all

2.4.删除配置:

C:\Users\Administrator>mysql_config_editor remove --login-path=test

C:\Users\Administrator>mysql_config_editor print --all
[client]
[user1]
user = "host"
password = *****
port = 3306

  • 其中可删除项
    • -h,–host=name 添加host到登陆文件中
    • -G,–login-path=name 在登录文件中为login path添加名字(默认为client)
    • -p,–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
    • -u,–user 添加用户名到登陆文件中
    • -S,–socket=name 添加sock文件路径到登陆文件中
    • -P,–port=name 添加登陆端口到登陆文件中

2.5.重置配置:

mysql_config_editor reset --login-path=user1

2.6.使用login-path登录:

mysql --login-path=test

若要登录其他主机、其他端口,或者添加其他额外参数,直接在上述命令后添加即可

2.6.1.登录host1:poet1上的MySQL

mysql --login-path=test  -h host1 -P port1

2.6.2.登录host1:poet1上的MySQL中的test_db库

mysql --login-path=test  -h host1 -P port1 test_db

3.参考:

MySQL :: MySQL 5.7 Reference Manual :: 4.6.6 mysql_config_editor — MySQL Configuration Utility

4.实际配置命令

 
  1. mysql_config_editor57 set --login-path=xxx --user=xxx --password --host=xxx --port=3306

  2. echo 'alias conn_xxx="mysql --login-path=xxx"' >> ~/.bashrc

  3. . ~/.bashrc

5.登陆效果

  • 输入 con_xxx即可访问数据库。

转载于:https://www.cnblogs.com/David-domain/p/11176474.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值