MySQL λ²μ μ΄ μ μ μ¬λΌκ°λ©΄μ μΈμ λΆν°μΈκ° mysql λͺ λ Ήμ΄λ‘ μ μμ λΉλ°λ²νΈλ₯Ό κ°μ΄ μ λ ₯νλ©΄ μλμ κ°μ΄ μμ νμ§ μλ€λ κ²½κ³ κ° λμ¨λ€.
$ mysql -hlocalhost -udb_user -pdb_password
mysql: [Warning] Using a password on the command line interface can be insecure.
μ μ€ν¬λ¦½νΈλ‘ DB μ μνλ μμ μ νλ κ²½μ° μμ κ°μ΄ λͺ λ Ήμ΄μ λΉλ°λ²νΈκΉμ§ κ°μ΄ μ λ ₯νλ κ²½μ°κ° λ§μλ° μ€νμ λμ§λ§ κ²½κ³ κ° λμ€λκ² λ§€μ° κ±°μ¬λ¦°λ€.
μ΄λ° κ²½μ°λ μλ 2κ°μ§ λ°©λ²μΌλ‘ ν΄κ²°μ΄ κ°λ₯νλ€.
λ°©λ²1)
κ³μ home path (리λ μ€ κΈ°μ€ /home/userid λ±) μ .my.cnf νμΌμ μμ±νκ³ μλμ κ°μ΄ λ΄μ©μ μ λ ₯νλ€.
[client]
host=localhost
user=db_user
password=db_password
μμ±ν νμ mysql λͺ λ Ήλ§ μ€ννλ©΄ λ°λ‘ μ μμ΄ κ°λ₯νλ€.
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47904
Server version: 8.0.23 Source distribution
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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>
μ΄λ κ² νλ©΄ κ°νΈνκ² μ μμ ν μ μμΌλ, μ§μ λ DB νκ³³λ§ μ μμ΄ κ°λ₯νκ³ , λ€λ₯Έ DB (host κΈ°μ€) μ μ μνλ €λ©΄ κΈ°μ‘΄μ²λΌ mysql μ -h μ΅μ μ μ¬μ©ν΄μ μ μμ ν΄μΌ νλ€.
DBλ₯Ό μ¬λ¬κ° μ¬μ©νλ κ²½μ° μλ λ°©λ²μΌλ‘ μ¬μ©νλ©΄ λλ€.
λ°©λ²2)
mysql_config_editor λͺ λ Ήμ μ¬μ©νμ¬ DB λ³λ‘ profile μ μμ±νλ€.
$ mysql_config_editor set --login-path=dev --host=localhost --user=root --password
μμ κ°μ΄ μ€ννλ©΄ λΉλ°λ²νΈ μ
λ ₯ ν둬ννΈκ° λμ€κ³ , λΉλ°λ²νΈλ₯Ό μ
λ ₯νλ©΄ μλ£λλ€.
κ³μ home path μ 보면 .mylogin.cnf νμΌμ΄ μμ±λμ΄ μμκ²μ΄λ€. (λ°μ΄λ리 νμμ΄λΌ λ΄μ©μ 보기 μ΄λ €μ)
--login-path μ κ°μ λ€λ₯΄κ² νμ¬ μ¬λ¬ DB μ 보λ₯Ό λ±λ‘ν΄ λκ³ , mysql μ μμ μλμ κ°μ΄ μ μνλ€.
$ mysql --login-path=dev
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9759
Server version: 8.0.23 Source distribution
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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_config_editor print --all
[dev]
user = "user1"
password = *****
host = "host1"
[stg]
user = "user2"
password = *****
host = "host2"
[prod]
user = "user3"
password = *****
host = "host3"
λ±λ‘λ μ 보 μμ
mysql_config_editor remove --login-path=dev
λ±λ‘λ λΉλ°λ²νΈλ μνΈν λμ΄μ .mylogin.cnf μ μ μ₯λμ΄ λ°λ‘ νμΈμ μ΄λ ΅μ§λ§, μλ λͺ λ Ήμ΄λ₯Ό ν΅ν΄ λΉλ°λ²νΈ νμΈμ΄ κ°λ₯νλ€.
$ my_print_defaults --show dev
--user=user1
--password=password1
--host=host1