当前位置: 代码迷 >> 综合 >> 如何安全登入mysql server之Login Paths
  详细解决方案

如何安全登入mysql server之Login Paths

热度:54   发布时间:2023-12-19 16:34:00.0
1.mysql -uroot -poracle -h 
这种方式登入mysql ,非常不安全,其他可以通过 history fc 等看到相关用户的密码信息
[root@lixora ~]# fc -l
1150     mysql --login-path=lixora
1151     mysql --login-path=admin
1152     mysql -uroot -poracle   ---密码直接明文显示
1153     mysql -uroot -pmysql   ---密码直接明文显示
考虑到系统的安全问题,这种登入方式还是不要再用了

2.mysql -uroot -p
安全问题是已经避免了,但是对于维护人员来说好像有点麻烦,每次登server 时都要敲

3.这里建议采用一个相对安全,简单,快捷的登入方式 login-path:
配置如下:(loging-path可以自定义,缺省是client,若要登入多个server,不同账户,需要指定不同的login-path名,否者会覆盖原来的配置信息)
[root@lixora ~]# mysql_config_editor set --login-path=lixora --user=root --password
Enter password: 
缺省会在当前目录下生成一个隐藏文件 .mylogin.cnf 这个文件是加密过的,也不是2进制文件
mylogin.cnf  的里的配置信息只能通过mysql_config_editor print --all 来查看,密码会自动用星号替代:


[root@lixora ~]# mysql_config_editor print --all
[client]
user = root
password = *****
[admin]
user = root
password = *****
[lixora]
user = root
password = *****


使用login-path 登入 mysql server:
[root@lixora ~]# mysql --login-path=admin

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 573
Server version: 5.6.10 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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 server登入配置信息:
[root@lixora ~]# mysql_config_editor set --login-path=lixora-remote --user=root --password  --host 1.1.1.1
Enter password: 
[root@lixora ~]#  mysql_config_editor print --all
[client]
user = root
password = *****
[admin]
user = root
password = *****
[lixora]
user = root
password = *****
[lixora-remote]
user = root
password = *****
host = 1.1.1.1

  相关解决方案