728x90
반응형

Command Line에서 SQL 수행 하는 방법은 -e 옵션을 사용하면 된다.

     -e : SQL 입력

     -s : silent

     -N : Header 없이 데이터만 출력

 

[root@mmysql ~]# mysql -e 'show databases;'

mysql: [Warning] Using a password on the command line interface can be insecure.

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

| tpcc               |

| tpch               |

+--------------------+

 

[root@mmysql ~]# mysql -s -e 'show databases;'

mysql: [Warning] Using a password on the command line interface can be insecure.

Database

information_schema

mysql

performance_schema

sys

tpcc

tpch

 

[root@mmysql ~]# mysql -s -N -e 'show databases;'

mysql: [Warning] Using a password on the command line interface can be insecure.

information_schema

mysql

performance_schema

sys

tpcc

tpch

 

 

그런데 password 노출 경우 다음과 같이 Warning 메시지가 출력된다.

mysql: [Warning] Using a password on the command line interface can be insecure.

 


패스워드를 저장시켜 놓고, 저장시켜 놓은 알리아스 명을 이용하여 로그 인을 하면 된다. 저장시키는 명령은 mysql_config_editor 이다.

저장된 알리아스와 패스워드는 유저의 홈디렉터리에 ~/.mylogin.cnf 파일에 저장된다.

 

[root@mmysql ~]# mysql_config_editor set --login-path=batch --host=localhost --user=root --password

Enter password:

[root@mmysql ~]# mysql_config_editor set --login-path=client --host=localhost --user=root --password

Enter password:

[root@mmysql ~]# mysql_config_editor print --all

[batch]

user = root

password = *****

host = localhost

[client]

user = root

password = *****

host = localhost


[root@mmysql ~]# mysql_config_editor remove --login-path=client


[root@mmysql ~]# mysql_config_editor print --all

[batch]

user = root

password = *****

host = localhost

 

[root@mmysql ~]# mysql --login-path=batch

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 317

Server version: 5.7.13-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> exit

Bye

 

 

[root@mmysql ~]# mysql --login-path=batch -s

mysql>

 

[root@smysql ~]# mysql --login-path=batch  -e 'show slave status\G;' | grep -E 'Errno|Seconds_Behind_Master|Error'

                   Last_Errno: 0

                   Last_Error:

        Seconds_Behind_Master: 0

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_SQL_Errno: 0

               Last_SQL_Error:

      Last_IO_Error_Timestamp:

     Last_SQL_Error_Timestamp: 

반응형

+ Recent posts