본문 바로가기

리눅스

MySQL login-path(mysql_config_editor) 사용하는 방법

728x90

MySQL login-path(mysql_config_editor) 사용하는 방법

MySQL의 mysql_config_editor를 사용하면 MySQL 서버에 로그인 정보를 저장하고 이를 간편하게 사용할 수 있습니다. 이를 통해 보안상의 이점과 함께 MySQL 명령어 라인에서 비밀번호를 입력하지 않고도 로그인할 수 있습니다.(MySQL 서버 연결에 대한 자격정보를 저장하는 유틸리티)

1. 로그인 정보 저장하기

mysql_config_editor를 사용하여 로그인 정보를 저장합니다. 아래와 같이 명령어를 실행합니다.

mysql_config_editor set --login-path=mylogin -u your_username -p

위 명령어에서 다음과 같은 항목을 지정해야 합니다.

 

  • --login-path: 로그인 경로 이름으로, 사용자가 지정하는 이름입니다. 여기서는 mylogin으로 지정하였습니다. 이는 로그인 정보를 저장할 고유한 이름입니다.
  • -u: MySQL 사용자 이름으로, 여기서는 사용자의 MySQL 계정 이름을 지정합니다.
  • -p: MySQL 사용자 비밀번호를 입력하라는 프롬프트가 표시됩니다. 여기서 실제 비밀번호를 입력합니다.

비밀번호를 입력한 후, 정보가 성공적으로 저장되면 다음과 같은 메시지가 표시됩니다: Warning: Stored password entry 'mylogin' has been added.

2. 로그인 경로로 MySQL 접속하기

이제 mysql_config_editor에 저장한 로그인 정보를 사용하여 MySQL 서버에 접속할 수 있습니다. 아래와 같이 명령어를 실행합니다.

mysql --login-path=mylogin

위 명령어에서 --login-path 옵션 다음에 저장한 로그인 경로 이름인 mylogin을 지정합니다. 이렇게 하면 해당 경로에 저장된 사용자 이름과 비밀번호를 사용하여 MySQL 서버에 로그인합니다. 추가로 다른 옵션을 사용하여 MySQL 서버에 접속할 수도 있습니다.

 

로그인 경로로 MySQL 접속 시 비밀번호를 별도로 입력할 필요가 없으므로, 보안상의 이점이 있습니다. 또한, 스크립트나 자동화된 작업에서 MySQL 접속 시 편리하게 사용할 수 있습니다.

 

주의: mysql_config_editor에 저장된 정보는 해당 사용자의 홈 디렉토리에 .mylogin.cnf 파일로 저장됩니다. 따라서 해당 사용자의 홈 디렉토리 내에 이 파일이 생성되어 있는지 확인하세요. 만약 해당 사용자로 로그인하는데 문제가 있다면, 파일 권한을 확인하고 문제를 해결하세요.

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 = *****
728x90
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.

 

728x90