MySQL 5.6 配置安全的加密密码
发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,在shell脚本中,通常要配置数据库的明文密码,这是不安全的。在MySQL 5.6版本以后,可以配置安全的加密密码文件,之后可以使用加密后的密码文件连接数据库,而不需要输入明文密码。为本地root用户
千家信息网最后更新 2025年01月21日MySQL 5.6 配置安全的加密密码在shell脚本中,通常要配置数据库的明文密码,这是不安全的。在MySQL 5.6版本以后,可以配置安全的加密密码文件,之后可以使用加密后的密码文件连接数据库,而不需要输入明文密码。
为本地root用户配置安全加密密码
[root@localhost ~]# mysql_config_editor set --user=root --password
Enter password:
尝试连接数据库
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 179
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
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> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> exit
Bye
到家目录,查看加密密码文件,可以看到里面的乱码
[root@localhost ~]# cd
[root@localhost ~]# cat .mylogin.cnf
?
?#[root@localhost ~]# p_?EQ!?a\S??T SB??hH?XJ?-&?P?-/?|m5?
配置指定的远程数据库连接用户
[root@localhost ~]# mysql_config_editor set --login-path=remote --host=192.168.56.101 --user=ss7 --password
Enter password:
查看配置过的加密密码清单
[root@localhost ~]# mysql_config_editor print --all
[client]
user = root
password = *****
[remote]
user = ss7
password = *****
host = 192.168.56.101
尝试连接数据库
[root@localhost ~]# mysql --login-path=remote
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 181
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
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> select user();
+--------------------+
| user() |
+--------------------+
| ss7@192.168.56.101 |
+--------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
通过--login-path选项连接root本地用户
[root@localhost ~]# mysql --login-path=client
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 182
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
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> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
为本地root用户配置安全加密密码
[root@localhost ~]# mysql_config_editor set --user=root --password
Enter password:
尝试连接数据库
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 179
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
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> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> exit
Bye
到家目录,查看加密密码文件,可以看到里面的乱码
[root@localhost ~]# cd
[root@localhost ~]# cat .mylogin.cnf
?
?#[root@localhost ~]# p_?EQ!?a\S??T SB??hH?XJ?-&?P?-/?|m5?
配置指定的远程数据库连接用户
[root@localhost ~]# mysql_config_editor set --login-path=remote --host=192.168.56.101 --user=ss7 --password
Enter password:
查看配置过的加密密码清单
[root@localhost ~]# mysql_config_editor print --all
[client]
user = root
password = *****
[remote]
user = ss7
password = *****
host = 192.168.56.101
尝试连接数据库
[root@localhost ~]# mysql --login-path=remote
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 181
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
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> select user();
+--------------------+
| user() |
+--------------------+
| ss7@192.168.56.101 |
+--------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
通过--login-path选项连接root本地用户
[root@localhost ~]# mysql --login-path=client
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 182
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
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> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
密码
加密
配置
数据
数据库
安全
文件
用户
明文
尝试
乱码
清单
版本
目录
脚本
这是
输入
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发加著作权费用翻倍
靖江购买网络技术解决方案
sql数据库建立代码
政府机关 维护网络安全
ftp服务器即时存储
网络安全怎么学python
网络安全操作系统维护
惯彻执行《网络安全法》
创建网站连接数据库失败
尤溪网络技术
宜昌市网络安全支撑单位
域服务器好处
php中修改数据库名称
软件开发英语重要吗
网络安全不仅是一个部门的事
阿里云服务器 负载均衡
上海其加软件开发公司
手机软件开发授权书
工厂需要软件开发工程师吗
数据库监测系统
怎么用手机做网络安全维护
网络安全操作系统维护
郑州网络安全站
设置微信号服务器忙
上海昌硕软件开发主要干什么
怀化软件开发培训多少钱
数据库查询最大值的数据
潮汕app软件开发大概多少钱
小型数据库使用方法
我的世界服务器怎么刷钻石