一、一键安装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>

【shell 每日一练7】一键安装mysql5.7,以及密码及策略修改的更多相关文章

  1. shell脚本一键安装mysql5.7.x

    使用脚本一键安装mysql5.7.x,初始化数据库.启动数据库---- mysql版本号:源代码mysql5.7.10 linux版本号:centos6.5 x86_64 #!/bin/bash GR ...

  2. shell脚本一键安装mysql5.7.x(免安装版)

    使用脚本一键安装mysql5.7.x,初始化数据库,启动数据库---- mysql版本:源码mysql5.7.10 linux版本:centos6.5 x86_64 #!/bin/bash GROUP ...

  3. 【shell 每日一练6】初始化安装Mysql并修改密码

    一.简单实现mysql一键安装 参考:[第二章]MySQL数据库基于Centos7.3-部署 此脚本前提条件是防火墙,selinux都已经设置完毕: [root@web130 ~]# cat Inst ...

  4. 一键安装MySQL5.6.43脚本

    [root@lamp ~]# cat /server/scripts/mysql-5.6.43_install.sh #!/bin/bash #卸载系统自带的Mysql /bin/rpm -e $(/ ...

  5. mysql5.7忘记密码时,修改root密码

    (1).由于MySQL5.7在安装完后,第一次启动时,会在root目录下生产一个随机的密码,文件名为 .mysql_secret 所以,登录时需要用随机密码登录,然后通过以下命令修改密码 “SET P ...

  6. 《oracle每日一练》免安装Oracle客户端使用PL/SQL

    免安装Oracle客户端使用PL/SQL Oracle客户端挺招人烦的,部署连接它的应用通常需要先安装它的客户端,安装程序要求在目标机器上写注册表,假设你没有洁癖的话,你仍可能被下面的事情绊住:当你的 ...

  7. CentOS6.5一键安装MySQL5.5.32(源码编译)

    ###################################################mysql_install.sh                                 ...

  8. 一键安装mysql5.6

    #!/bin/bash # @Name:install_mysql.sh # @Author:Eivllom # @Create -- # @Modify -- app_soft="/app ...

  9. mysql5.7安装部署后初始密码查看以及修改

    一.查看初始密码以下两种方法: 1.找到自己的error.log日志文件,执行自己的命令,红色标记的部分为初始化密码. grep 'temporary password' /data/mysql/er ...

随机推荐

  1. 解决error possibly undefined macro AC_MSG_ERROR

    问题 出现如下缺少宏的问题 error: possibly undefined macro: AC_MSG_ERROR error: possibly undefined macro: AC_SUBS ...

  2. DPDK硬件盒子的初步安装测试

    DPDK硬件盒子 接口 两个USB接口:用于连接键盘等. HDMI接口:高清晰度多媒体接口,用于连接显示器,但是一般的电脑显示器使用的是VGA口,可以用一个转接头连接. 两个RJ接口:可接入网线连接. ...

  3. CentOS7网络连接问题以及重启网络服务失败

    1.重启网络服务失败 在运行“/etc/init.d/network restart”命令时,出现错误“Job for network.service failed. See 'systemctl s ...

  4. Servlet基础知识总结

    Servlet是JavaWeb应用开发的核心组件.Servlet运行在Servlet容器中(例如最常用的Tomcat),它可以为各种客户请求提供相应服务.Servlet可以轻松完成以下任务: 动态生成 ...

  5. SessionStroage和locationStorage的思考

    从理论上讲 LocalStroage 内存更大,存储时间更为持久,作用域更大.那么SessionStroage有存在的必要吗?有什么样的应该场景是必须用seessionStroage 而不能使用Loc ...

  6. 弹性布局解决ios输入框遮挡input

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. PhpStorm 全局查找的快捷键

    本页面查找 :   ctrl  + f 全局查找 : ctrl + shift + f 自己定义 :文件 -> 设置  -> 快捷键  ->  修改

  8. Node.js http.createServer 简单服务配置

    基本实现: var http = require("http"); var server = http.createServer(function (req, res) { if ...

  9. [译]C语言实现一个简易的Hash table(7)

    上一章我们讲了如何根据需要动态设置hash表的大小,在第四章中,我们使用了双重哈希来解决hash表的碰撞,其实解决方法有很多,这一章我们来介绍下其他方法. 本章将介绍两种解决hash表碰撞的方法: 拉 ...

  10. Delphi主线程重入而导致程序卡死的解决方案

    Delphi的线程可以通过调用AThread.Synchronize(AProc),可以将Proc放入主线程中同步运行,此时AThread将挂起,直到主线程执行完AProc. 如果有BThread,调 ...