MYSQL报警:Warning: Using a password on the command line interface can be insecure.

问题描述:执行下面的语句,sql是执行成功了,但是出现了一个报警,报警看上去始终不舒服

mysql -hip -Pport -uuser -ppassword -e "use db;delete from tb;";
Warning: Using a password on the command line interface can be insecure.

解决方法:报警的意思是“在命令行输入密码是不安全的”,解决方法是将用户名和密码写入配置文件,然后在命令行用参数的形式引入文件

.config文件内容如下:

[mysql]
user=abc
password=abc123
mysql --defaults-extra-file=~/.config -hip -Pport -e "use db;delete from tb;";

如果.config文件中的user、password均正确,那么上面的sql会执行成功,并且没有任何报警。

附:可以变动的地方及注意点

1、.config文件中的第一行除了可以是[mysql],还可以是[client]。

2、.config文件中除了password是必须的其他参数都是可选的,可以写在配置文件中,也可以写在命令行中。

3、--defaults-extra-file参数必须放在第一位。

4、当mysql或mysqldump使用遇到困难时,除了可以问旁边的大神,还可以用mysql --help来帮助解决问题。

原文地址:https://www.cnblogs.com/sunflower627/p/7265012.html