mysql_config_editor & my_print_defaults

1.mysql_config_editor

mysql_config_editor用于给指定的连接和密码生成一个家目录下的隐藏密码文件.mylogin.cnf,避免密码直接暴露(不是绝对保密,后续有解法)

  • 创建用户sbcrm
cnsz92vl00120.cmftdc.cn:lpc :master > mysql-l 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 70
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2017, 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.

mysql> create  user sbcrm identified by '123456^Cmr';
Query OK, 0 rows affected (0.01 sec)
  • mysql_config_editor配置–login-path
cnsz92vl00120.cmftdc.cn:test :master > mysql_config_editor set --login-path=sbcrm --user=sbcrm -P4308 -h127.0.0.1 -p
Enter password:      --------输入密码
cnsz92vl00120.cmftdc.cn:test :master > mysql_config_editor print --login-path=sbcrm
[sbcrm]
user = sbcrm
password = *****
host = 127.0.0.1
port = 4308
  • 登录验证
cnsz92vl00120.cmftdc.cn:test :master > mysql --login-path=sbcrm
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 754
Server version: 5.7.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

mysql> 
mysql> exit
Bye

2.my_print_defaults

mysql_config_editor print 只能查看有哪些–login-path和部分配置,明文密码其实看不到,那如何获取明文密码呢,my_print_defaults命令可以搞定

cnsz92vl00120.cmftdc.cn:test :master > mysql_config_editor print --login-path=sbcrm
[sbcrm]
user = sbcrm
password = *****
host = 127.0.0.1
port = 4308

cnsz92vl00120.cmftdc.cn:test :master > my_print_defaults -s sbcrm
--user=sbcrm
--password=123456^Cmr
--host=127.0.0.1
--port=4308


#########my_print_defaults命令可以通过help了解###########
cnsz92vl00120.cmftdc.cn:test :master > my_print_defaults --help
my_print_defaults  Ver 1.6 for linux-glibc2.12 at x86_64
Copyright (c) 2000, 2017, 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.

Prints all arguments that is give to some program using the default files
Usage: my_print_defaults [OPTIONS] groups
  -c, --config-file=name 
                      Deprecated, please use --defaults-file instead. Name of
                      config file to read; if no extension is given, default
                      extension (e.g., .ini or .cnf) will be added
  -#, --debug[=#]     This is a non-debug version. Catch this and exit
  -c, --defaults-file=name 
                      Like --config-file, except: if first option, then read
                      this file only, do not read global or per-user config
                      files; should be the first option
  -e, --defaults-extra-file=name 
                      Read this file after the global config file and before
                      the config file in the users home directory; should be
                      the first option
  -g, --defaults-group-suffix=name 
                      In addition to the given groups, read also groups with
                      this suffix
  -e, --extra-file=name 
                      Deprecated. Synonym for --defaults-extra-file.
  -n, --no-defaults   Ignore reading of default option file(s), except for
                      login file.
  -l, --login-path=name 
                      Path to be read from under the login file.
  -s, --show          Show passwords in plain text.
  -?, --help          Display this help message and exit.
  -v, --verbose       Increase the output level
  -V, --version       Output version information and exit.

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf /rh/mysql/base/my.cnf ~/.my.cnf 

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
config-file                       my
defaults-file                     my
defaults-extra-file               (No default value)
defaults-group-suffix             (No default value)
extra-file                        (No default value)
login-path                        (No default value)
show                              FALSE

Example usage:
my_print_defaults --defaults-file=example.cnf client mysql

你可能感兴趣的:(MySQL)