리눅스

MySQL Login Path 설정하는 방법

변군이글루 2021. 8. 31. 15:24
반응형

MySQL Login Path(mysql_config_editor) 설정하는 방법

MySQL에서 Login Path 설정을 통해 로그인 정보를 암호화된 형태로 저장하고 쉽게 접근할 수 있습니다. 이를 설정하면 MySQL 접속 시마다 비밀번호를 입력할 필요가 없으면서도 보안을 유지할 수 있습니다.(MySQL 서버 연결에 대한 자격정보를 저장하는 유틸리티)

1. mysql_config_editor 명령어

mysql_config_editor는 MySQL 로그인 정보를 안전하게 저장하고 관리하기 위한 도구입니다. MySQL 클라이언트와 연결할 때 반복적으로 입력해야 하는 로그인 정보를 ~/.mylogin.cnf 파일에 암호화하여 저장하고 자동으로 불러옵니다.

mysql_config_editor [command] [options]

주요 명령어 및 옵션

  • add: 새 로그인 정보를 저장합니다.
  • remove: 저장된 로그인 정보를 삭제합니다.
  • print: 현재 저장된 로그인 정보를 출력합니다.
    • --user: 사용자 이름을 지정합니다.
    • --password: 비밀번호를 지정합니다.
    • --host: 호스트 주소를 지정합니다.
    • --port: 포트를 지정합니다.

2. mysql_config_editor로 Login Path 설정하기

mysql_config_editor를 사용해 원하는 login-path 이름으로 MySQL 로그인 정보를 저장할 수 있습니다.

mysql_config_editor set --login-path=<별칭> --host=<호스트> --user=<사용자명> --password

mylogin이라는 별칭으로 root 사용자 정보를 localhost 서버에 저장합니다.

mysql_config_editor set --login-path=mylogin --host=localhost --user=root --password

비밀번호를 입력한 후 정보가 성공적으로 저장되면 다음과 같은 메시지가 표시됩니다.

 Warning: Stored password entry 'mylogin' has been added.

3. Login Path 별칭으로 MySQL 접속하기

설정한 Login Path를 사용해 MySQL에 쉽게 접속할 수 있습니다. --login-path=<별칭> 옵션을 사용하면 비밀번호를 입력하지 않고도 저장된 로그인 정보로 접속이 가능합니다.

mysql --login-path=mylogin

4. 저장된 Login Path 목록 확인하기

mysql_config_editor를 통해 저장된 모든 Login Path 설정을 확인할 수 있습니다.

mysql_config_editor print --all

특정 별칭만 확인하려면 --login-path=<별칭> 옵션을 추가해 원하는 Login Path의 세부 정보를 볼 수 있습니다.

mysql_config_editor print --login-path=mylogin

5. Login Path 삭제하기

사용하지 않는 Login Path는 삭제할 수 있습니다.

mylogin이라는 별칭을 삭제하려면 다음과 같이 실행합니다.

mysql_config_editor remove --login-path=mylogin

6. Login Path 설정 파일 위치

Login Path 설정 정보는 ~/.mylogin.cnf 파일에 암호화된 형태로 저장됩니다. 이 파일은 기본적으로 사용자만 접근할 수 있는 권한으로 설정됩니다.

~/.mylogin.cnf 파일은 수동으로 수정하지 않도록 하며, mysql_config_editor 명령어를 통해 안전하게 관리하는 것이 좋습니다.

728x90

login-path 사용 예시

login-path 설정

mysql_config_editor set --login-path=node1-mysql --host=localhost --user=root --port=3306 --password

(또는)

mysql_config_editor set -G node1-mysql -u root -p
$ mysql_config_editor set -G node1-mysql -u root -p
Enter password:

login-path 조회

mysql_config_editor print --all
$ mysql_config_editor print --all
[node1-user]
user = root
password = *****
[node1-mysql]
user = root
password = *****
mysql_config_editor print --login-path=node1-mysql

(또는)

mysql_config_editor print -G node1-mysql
$ mysql_config_editor print -G node1-mysql
[node1-mysql]
user = root
password = *****

login-path를 이용한 로그인 테스트

mysql --login-path=node1-mysql
$ mysql --login-path=node1-mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.7.14-log MySQL Community Server (GPL)

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

login-path 제거

mysql_config_editor remove -G node1-user

login-path 리셋

mysql_config_editor reset

login-path 구성 파일(.mylogin.cnf)의 위치

$ ls -l ~/.mylogin.cnf
-rw------- 1 root root 100 Sep  1 00:04 /root/.mylogin.cnf

login-path help

$ mysql_config_editor --help
mysql_config_editor Ver 1.0 Distrib 5.7.14, for Linux on x86_64
Copyright (c) 2012, 2016, 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.
Usage: mysql_config_editor [program options] [command [command options]]
  -#, --debug[=#]     This is a non-debug version. Catch this and exit.
  -?, --help          Display this help and exit.
  -v, --verbose       Write more information.
  -V, --version       Output version information and exit.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
verbose                           FALSE

Where command can be any one of the following :
       set [command options]     Sets user name/password/host name/socket/port
                                 for a given login path (section).
       remove [command options]  Remove a login path from the login file.
       print [command options]   Print all the options for a specified
                                 login path.
       reset [command options]   Deletes the contents of the login file.
       help                      Display this usage/help information.

 

참고URL

- MySQL Documentation : 6.6.7 mysql_config_editor — MySQL Configuration Utility

 

728x90
반응형