使用mysql_config_editor 管理mysql登录

如果不想每次登录mysql 数据库时都输入密码时,可以使用
如下命令进行密码管理

1、mysql_config_editor set  --login-path=mysql_3306 --host=10.10.10.10 --user=root --port=3306 --password

2、mysql_config_editor  set --login-path=mysql_3307 --socket=/data/3307/tmp/mysql.sock --port=3307 --user=root --password
登录
mysql --login-path=mysql_3306

mysql --login-path=mysql_3307

查看详细信息:

mysql_config_editor print --login-path=mysql_3306
[mysql_3306]
user = root
password = *****
socket = /data/3306/tmp/mysql.sock


修改信息

mysql_config_editor reset --log-path=mysql_3306 --user=root --password --host=10.10.10.10

[root@db2 ~]# mysql_config_editor  set --help
mysql_config_editor Ver 1.0 Distrib 5.7.26, for linux-glibc2.12 on x86_64
Copyright (c) 2012, 2019, 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.

MySQL Configuration Utility.

Description: Write a login path to the login file.
Usage: mysql_config_editor [program options] [set [command options]]
  -?, --help          Display this help and exit.
  -h, --host=name     Host name to be entered into the login file.
  -G, --login-path=name 
                      Name of the login path to use in the login file. (Default
                      : client)
  -p, --password      Prompt for password to be entered into the login file.
  -u, --user=name     User name to be entered into the login file.
  -S, --socket=name   Socket path to be entered into login file.
  -P, --port=name     Port number to be entered into login file.
  -w, --warn          Warn and ask for confirmation if set command attempts to
                      overwrite an existing login path (enabled by default).
                      (Defaults to on; use --skip-warn to disable.)

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
[root@db2 ~]# mysql_config_editor --print
mysql_config_editor: [ERROR] unknown option '--print'
[root@db2 ~]# mysql_config_editor print

[root@db2 ~]# mysql_config_editor print --login-path=mysql_3306
[mysql_3306]
user = root
password = *****
socket = /data/3306/tmp/mysql.sock

你可能感兴趣的:(MySQL,mysql,数据库)