情景再现
[root@VM-8-16-centos script]# mysql -hxxxx -uhewieliao -pxxx
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 182411
Server version: 8.0.18 Source distribution
Copyright (c) 2000, 2021, 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>
[root@VM-8-16-centos ~]# mysqldump -hxxx -uhewieliao -pxxx solo > /tmp/solo.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
在命令行直接使用-p加上明文密码会在第二行出现警告的提示。
处理方式
使用环境变量
[root@VM-8-16-centos ~]# export MYSQL_PWD=${password}
[root@VM-8-16-centos ~]# mysql -hxxx -uhewieliao
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 182419
Server version: 8.0.18 Source distribution
Copyright (c) 2000, 2021, 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>
[root@VM-8-16-centos ~]# export MYSQL_PWD=${password}
[root@VM-8-16-centos ~]# mysqldump -hxxxx -uhewieliao solo > /tmp/solo.sql
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
在配置文件中配置
[client]
user = "whatever"
password = "whatever"
host = "whatever"
[mysqldump]
user = "whatever"
password = "whatever"
host = "whatever"
mysql_config_editor
重定向
[root@VM-8-16-centos ~]# mysqldump -hxxxx -uhewieliao -pxxxx solo > /tmp/solo.sql 2> /dev/null
[root@VM-8-16-centos ~]# mysql -hxxxx -uhewieliao -pxxxx 2> /dev/null
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 182426
Server version: 8.0.18 Source distribution
Copyright (c) 2000, 2021, 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命令使用-p选项出现的警告去除方式
作者:hewieliao
地址:https://hewieliao.com/articles/2022/09/18/1663515566663.html