一、一键安装Mysql脚本

[root@uat01 ~]# cat InstallMysql01.sh
#!/bin/bash
#--
#旅行者-Travel
#.安装wget
yum -y install wget
#、下载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-.noarch.rpm
if [ $? -eq ];then
rm -rf /etc/yum.repos.d/mysql80-community-release-el7-.noarch*
fi
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
yum -y install mysql-community-server
sleep
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
if [ $? -eq ];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
Server version: 5.7. Copyright (c) , , 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=;
Query OK, rows affected (0.00 sec) mysql> set global validate_password_length=;
Query OK, rows affected (0.00 sec) mysql> alter user 'root'@'localhost' identified by 'Yanglt123.';
Query OK, rows affected (0.00 sec) mysql> flush privileges;
Query OK, rows affected (0.00 sec) mysql> quit

三、数据库密码策略:

1、查看数据库策略:

因为上文已经将 validate_password_length 值改为4,所以下文显示为4,默认情况下为8

[root@uat01 ~]# mysql -uroot -p
.....
Server version: 5.7. MySQL Community
......
mysql> show variables like 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | |
| validate_password_mixed_case_count | |
| validate_password_number_count | |
| validate_password_policy | LOW |
| validate_password_special_char_count | |
+--------------------------------------+-------+
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=;
Query OK, rows affected (0.00 sec)
mysql> set global validate_password_length=;
Query OK, rows affected (0.00 sec),
mysql> flush privileges;
Query OK, rows affected (0.00 sec)

4、修改简单密码测试

mysql> alter user 'root'@'localhost' identified by ''; #测试发现密码长度最少为4位
Query OK, rows affected (0.00 sec) mysql> flush privileges;
Query OK, 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
Server version: 5.7. MySQL Community Server (GPL) Copyright (c) , , 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>

最新文章

  1. 为你的Web程序加个启动画面
  2. 一个简单的webservice的demo(下)winform异步调用webservice
  3. 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)
  4. js多文件上传
  5. UML的类图、时序图表示方法以及惯例
  6. TCP/IP Four Layer Protocol Format Learning
  7. 什么是A记录?MX记录?CNAME记录?它们都有些什么用途?
  8. PHP 文件上传类
  9. Java String类中的intern()方法
  10. 关于Resources.LoadAssetAtPath
  11. C复习手记(Day1)
  12. 【Linux】给Linux配置SNMP用户以及协议
  13. MulticastSocket绑定端口的问题
  14. CSharpGL(42)借助帧缓存实现渲染到纹理(RenderToTexture)
  15. MVC4 5分页控件,支持Ajax AjaxOption支持
  16. iOS 运行时使用(交换两个方法)
  17. k8s调度的亲和性和反亲和性
  18. Python 传值和传址 copy/deepcopy
  19. [leetcode]211. Add and Search Word - Data structure design添加查找单词 - 数据结构设计
  20. 作业 20181127-3 互评Beta版本

热门文章

  1. IT经理苏大强:我不吃,我不喝,我要赶项目!
  2. 如何通过github上传项目并在readme.md中展示图片二维码
  3. 正方形(类型:枚举、一级、C++)
  4. 【Linux】YUM源搭建
  5. MongoDB DBA 实践7-----MongoDB的分片集群操
  6. ruby安装devkit
  7. python教程(三)·自定义函数
  8. SSL&TlS握手
  9. git——本地项目上传到git
  10. 20155308 实验四 Android开发基础