MYSQLコマンドラインパスワード入力警告問題「mysql:[Warning]」解決

2491 ワード

1.1問題表示
[root@localhost ~]# mysql -uroot -p1234567
mysql: [Warning] Using a password on the command line interface can be insecure.

1.2解決方法
1.2.1方法一
1、マスタープロファイルにパスワードを書き込む
[root@localhost ~]# vim /etc/my.cnf
[mysqldump]
user=root
password=1234567

[mysql]
user=root
password=1234567

2、直接コマンドでログインして、アカウントのパスワードを入力する必要はありません
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.18-log Source distribution
Copyright (c) 2000, 2017, 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> 

1.2.2方法2
1、自動配置MYSQL暗号化パスワード
この操作はユーザーホームディレクトリの下に隠しファイル「.mylogin.cnf」を生成します.中にはMYSQLの暗号文のパスワードが記録されています.構成されている限り、私たちも直接コマンドでログインし、アカウントのパスワードを入力する必要はありません.キャンセルしたい場合は、このファイルを削除すればいいです.
[root@localhost ~]# mysql_config_editor set --user=root --host=localhost --port=3306 --password
Enter password:     

2、直接コマンドでログインして、アカウントのパスワードを入力する必要はありません
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.18-log Source distribution
Copyright (c) 2000, 2017, 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> 

1.2.3方法3
1、直接コマンドでログインし、エラーメッセージを遮断する
アラーム情報は標準エラーであるため、標準エラーの出力情報を空に出力することができます.
[root@localhost ~]# mysql -uroot -p1234567 2>/dev/null
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.7.18-log Source distribution
Copyright (c) 2000, 2017, 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>

転載先:https://blog.51cto.com/10978134/2176000