Cs

17. 리눅스(Linux) 쉘 스크립트(Shell Script) - DB 백업 스크립트 - Mysql_config_editor

ITSEONG 2022. 4. 28. 20:06

DB 백업 스크립트를 작성할 때 스크립트에 패스워드를 직접 입력하는 건 위험하다. 누군가 쉘 스크립트에 접근을 한다면 db의 정보가 유출되기 때문이다. 

 

이에 mysql에서는 5.6 버전이후부터 로그인 정보를 난독화 시켜줄 수 있는 유틸리티를 제공한다.

[client]
user = mydefaultname
password = mydefaultpass
host = 127.0.0.1
[mypath]
user = myothername
password = myotherpass
host = localhost

로그인 정보를 등록하기 위해서는 mysql_config_editor set을 이용하여 등록한다.

$> mysql_config_editor set --login-path=client
         --host=localhost --user=localuser --password
Enter password: enter password "localpass" here
$> mysql_config_editor set --login-path=remote
         --host=remote.example.com --user=remoteuser --password
Enter password: enter password "remotepass" here

set을 이용하여 등록된 정보를 확인하고 할때에는  print를 사용한다.

#특정 이름의 정보 출력
mysql_config_editor print --login-path=name

#모든 정보 출력
mysql_config_editor print --all

로그인 정보를 제거하고 싶다면

# mypath의 user의 정보만 제거할때
mysql_config_editor remove --login-path=mypath --user

# mypath를 제거할때
mysql_config_editor remove --login-path=mypath

reset은 로그인 경로 파일의 전체 내용을 비웁니다. 

 

오늘은 쉘스크립트를 작성할 때 mysql정보를 직접 노출이 아닌 mysql의 유틸을 이용하여 로그인 정보를 작성하는 법을 알아보았다.

 

출처 : https://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.html

반응형