Rootop 服务器运维与web架构

mysql命令行提示mysql: [Warning] Using a password on the command line interface can be insecure问题

在命令行下执行mysql命令,指定密码参数会提示不安全。

[root@db2 ~]# mysql -uroot -p"xxx" -e "show slave status\G;" |grep Running | grep -v State | grep Yes | wc -l
mysql: [Warning] Using a password on the command line interface can be insecure.
2

抑制此提示有2种方法;
方法1:加上 2>&1

[root@db2 ~]# mysql -uroot -p"xxx" -e "show slave status\G;" 2>&1 |grep Running | grep -v State | grep Yes | wc -l
2

方法2、使用加密登录。
使用mysql_config_editor命令生成认证文件

[root@db2 ~]# /usr/local/mysql/bin/mysql_config_editor set --login-path=local -h localhost --user=root --port=3306 --password
Enter password: 

# 指定认证信息登录

[root@db2 ~]# mysql --login-path=local
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 8.0.33 MySQL Community Server - GPL

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> exit
Bye

# 设置一个远程连接

[root@db2 ~]# /usr/local/mysql/bin/mysql_config_editor set --login-path=r247 --user=root --password --host=192.168.12.247

mysql_config_editor 会在用户家目录下生成一个.mylogin.cnf隐藏文件,并且是加密无法直接读取的。

# 打印指定登录路径

[root@db2 ~]# /usr/local/mysql/bin/mysql_config_editor print --login-path=local
[local]
user = "root"
password = *****
host = "localhost"
port = 3306

# 打印所有

[root@db2 ~]# /usr/local/mysql/bin/mysql_config_editor print --all

# mysqldump 备份使用登录路径信息。

[root@db2 ~]# mysqldump --login-path=local test > test.sql

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/5369.html

作者:Venus

服务器运维与性能优化

评论已关闭。