使用–login-path实现
如果使用login-path,需要通过mysql_config_editor来完成基础配置。
mysql_config_editor的命令提示如下:
[zs@local]$mysql_config_editor set --help
参数:
-?, --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.)
可以通过一个命令来完成配置,制定这个无密码登录的别名为 : zhang
[localhost@root]#mysql_config_editor set --login-path=zhang --user=root --host=localhost --password --socket=/tmp/mysql.sock
Enter password:
配置完成之后,会在当前路径下生成一个隐藏的文件 .mylogin.cnf
[localhost@root]#ll -la
如果要查看里面的明细信息,可以使用如下命令,当然密码是不会显示出来的
[localhost@root]#mysql_config_editor print --login-path=zhang
[zhang]
user=root
password=******
host=localhost
socket=/tmp/mysql.sock
登录:
mysql --login-path=zhang
禁用删除:
mysql_config_editor remove --login-path=zhang
再次查看就没有任何信息了。但是默认的login文件还是存在的