一键安装mysql5.7及密码策略修改方法
作者:旅行者-Travel 时间:2024-01-22 05:29:37
一、一键安装Mysql脚本
[root@uat01 ~]# cat InstallMysql01.sh
#!/bin/bash
#2018-10-13
#旅行者-Travel
#1.安装wget
yum -y install wget
#2、下载mysql的yum源
URL="https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm"
wget $URL -P /etc/yum.repos.d/
yum -y install yum-utils #如果没有该包,下边执行yum-config-manager不生效
yum -y install /etc/yum.repos.d/mysql80-community-release-el7-1.noarch.rpm
if [ $? -eq 0 ];then
rm -rf /etc/yum.repos.d/mysql80-community-release-el7-1.noarch*
fi
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
yum -y install mysql-community-server
sleep 5
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
if [ $? -eq 0 ];then
echo -e "install succefull"
result="`grep 'temporary password' /var/log/mysqld.log`"
p1="`echo $result |awk '{print $NF}'`"
echo "数据库密码为:$p1"
fi
[root@uat01 ~]#
二、修改策略和密码
执行完以上脚本可以看到Mysql的密码,如下方法登录修改策略,因为默认密码要求比较高,可以根据自己需求来决定是否更改策略:
install succefull
数据库密码为:9aTR&ok>f;1K
[root@uat01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23
Copyright (c) 2000, 2018, 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> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by 'Yanglt123.';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
三、数据库密码策略:
1、查看数据库策略:
因为上文已经将 validate_password_length 值改为4,所以下文显示为4,默认情况下为8
[root@uat01 ~]# mysql -uroot -p
.....
Server version: 5.7.23 MySQL Community
......
mysql> show variables like 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 4 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
mysql>
2、各项值说明
validate_password_policy:密码安全策略,默认MEDIUM策略
策略 | 检查规则 |
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度 ,测试发现最小值得为4。
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个
3、修改策略,跟上文第二操作一样
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec),
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4、修改简单密码测试
mysql> alter user 'root'@'localhost' identified by '1234'; #测试发现密码长度最少为4位
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
[root@uat01 ~]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
总结
以上所述是小编给大家介绍的一键安装mysql5.7及密码策略修改方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家大家的!
来源:https://www.cnblogs.com/yangleitao/archive/2018/10/13/9784726.html
标签:安装,mysql5.7,密码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python GUI库图形界面开发之PyQt5控件数据拖曳Drag与Drop详细使用方法与实例
2022-04-19 04:22:39
![](https://img.aspxhome.com/file/2023/8/108118_0s.png)
JS异步函数队列功能实例分析
2024-04-22 13:26:28
Python玩转Excel的读写改实例
2022-01-27 19:59:47
Python logging管理不同级别log打印和存储实例
2021-08-27 19:12:29
vue简单实现购物车结算功能
2024-05-28 15:54:57
![](https://img.aspxhome.com/file/2023/2/123122_0s.jpg)
keras:model.compile损失函数的用法
2023-11-23 08:44:21
解决Python import .pyd 可能遇到路径的问题
2023-06-30 14:33:33
![](https://img.aspxhome.com/file/2023/2/97652_0s.jpg)
python实现的分析并统计nginx日志数据功能示例
2023-07-30 20:08:15
MySQL数据备份之mysqldump的使用方法
2024-01-17 05:25:46
Django中自定义查询对象的具体使用
2021-05-26 03:11:18
Python爬虫自动化获取华图和粉笔网站的错题(推荐)
2023-08-14 02:05:42
![](https://img.aspxhome.com/file/2023/8/124288_0s.png)
如何使用PHP中的字符串函数
2024-05-11 10:01:59
如何理解Python中包的引入
2021-08-14 11:42:31
javascript限制用户只能输汉字中文的方法
2023-07-02 05:30:29
Vue实现自定义下拉菜单功能
2024-05-09 15:19:14
![](https://img.aspxhome.com/file/2023/3/126473_0s.png)
分别用marquee和div+js实现首尾相连循环滚动效果,仅3行代码
2024-04-18 10:55:26
Python实现的数据结构与算法之队列详解
2021-06-06 09:58:05
![](https://img.aspxhome.com/file/2023/2/88872_0s.png)
python中__call__内置函数用法实例
2022-06-04 11:46:32
python实现简单http服务器功能
2023-03-24 15:36:58
![](https://img.aspxhome.com/file/2023/9/120949_0s.jpg)
对python读取zip压缩文件里面的csv数据实例详解
2022-04-14 10:48:57
![](https://img.aspxhome.com/file/2023/7/103617_0s.jpg)