欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Mysql 安全登陆工具 mysql_config_editor

程序员文章站 2024-01-26 13:40:28
mysql_config_editor 帮助信息请查看 man mysql_config_editor 或 mysql_config_editor -? 或 mysql_config_editor set -? 该工具会在用户家目录生成二进制文件:.mylogin.cnf 该文件格式由选项组组成,每 ......

mysql_config_editor

帮助信息请查看
man mysql_config_editor 或 mysql_config_editor -? 或 mysql_config_editor set -?
该工具会在用户家目录生成二进制文件:.mylogin.cnf
该文件格式由选项组组成,每个选项组被称为login path ,仅包含特定选项: host, user, password, port and socket 用于用户验证。
 

用法:

mysql_config_editor set [command options] sets user name/password/host name/socket/port for a given login path (section). 
mysql_config_editor remove [command options] remove a login path from the login file.
mysql_config_editor print [command options] print all the options for a specified login path.
mysql_config_editor reset [command options] deletes the contents of the login file.
 

设置 login path

[root@mysql1 ~]# mysql_config_editor set -?

-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.

 

如:
mysql_config_editor set -g mypath -u root -p -s /u01/data/mysql5.7.25/mysql.sock
mysql_config_editor set -g user1 -u user1 -p -s /u01/data/mysql5.7.25/mysql.sock
 

显示 login path

mysql_config_editor print --all
mysql_config_editor print -g user1
[root@mysql1 ~]# mysql_config_editor print --all
[client] # 默认 login path
[mypath]
user = root
password = *****
socket = /u01/data/mysql5.7.25/mysql.sock
[mypath1]
user = root
password = *****
socket = /u01/data/mysql5.7.25/mysql.sock
[user1]
user = user1
password = *****
socket = /u01/data/mysql5.7.25/mysql.sock

 

删除 login path

mysql_config_editor remove -g user1
[root@mysql1 ~]# mysql_config_editor remove -g user1
[root@mysql1 ~]# mysql_config_editor print --all
[client]
[mypath]
user = root
password = *****
socket = /u01/data/mysql5.7.25/mysql.sock
[mypath1]
user = root
password = *****
socket = /u01/data/mysql5.7.25/mysql.sock

 

重置 login file

mysql_config_editor reset
[root@mysql1 ~]# mysql_config_editor reset
[root@mysql1 ~]# mysql_config_editor print --all  # 文件已被清空

 

使用 login path

mysql --login-path=mypath
mysqladmin  --login-path=mypath
[root@mysql1 ~]# mysqladmin --login-path=mypath status
uptime: 11918 threads: 1 questions: 18 slow queries: 0 opens: 106 flush tables: 1 open tables: 99 queries per second avg: 0.001