一键安装mysql5.7及密码策略修改方法

 更新时间:2018年10月14日 09:34:16   作者:旅行者-Travel  
这篇文章主要介绍了一键安装mysql5.7及密码策略修改方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

一、一键安装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及密码策略修改方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家大家的!

相关文章

  • MySQL中select语句使用order按行排序

    MySQL中select语句使用order按行排序

    本文介绍MySQL数据库中执行select查询语句,并对查询的结果使用order by 子句进行排序
    2016-04-04
  • mysql中用于数据迁移存储过程分享

    mysql中用于数据迁移存储过程分享

    mysql 数据迁移用的一个存储过程,需要的朋友可以收藏下。
    2011-05-05
  • MySQL创建全文索引分享

    MySQL创建全文索引分享

    使用索引是数据库性能优化的必备技能之一。在MySQL数据库中,有四种索引:聚集索引(主键索引)、普通索引、唯一索引以及我们这里将要介绍的全文索引(FULLTEXT INDEX)
    2017-01-01
  • MySQL中count(*)、count(1)和count(col)的区别汇总

    MySQL中count(*)、count(1)和count(col)的区别汇总

    count()函数是用来统计表中记录的一个函数,返回匹配条件的行数,下面这篇文章主要给大家总结介绍了关于MySQL中count(*)、count(1)和count(col)的区别,文中通过示例代码介绍的非常详细,需要的朋友可以参考下。
    2018-03-03
  • 数据库查询哪个对像里面包含什么字段方法语句

    数据库查询哪个对像里面包含什么字段方法语句

    在本篇文章里小编给大家整理的关于数据库查询哪个对像里面包含什么字段方法语句有需要的朋友们可以学习下。
    2019-08-08
  • 使用mysql中遇到的几个问题

    使用mysql中遇到的几个问题

    首先mysql不是可视化的,可以通过命令行进行操作,包括创建数据库、表、添加数据等等。那岂不是很不方便了吗?
    2009-07-07
  • MySQL全文索引实现简单版搜索引擎实例代码

    MySQL全文索引实现简单版搜索引擎实例代码

    这篇文章主要给大家介绍了关于MySQL全文索引实现简单版搜索引擎的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用MySQL具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-07-07
  • 浅谈MySQL分页Limit的性能问题

    浅谈MySQL分页Limit的性能问题

    这篇文章主要介绍了浅谈MySQL分页Limit的性能问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-08-08
  • 当Mysql行锁遇到复合主键与多列索引详解

    当Mysql行锁遇到复合主键与多列索引详解

    这篇文章主要给大家介绍了关于当Mysql行锁遇到复合主键与多列索引的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Mysql具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-09-09
  • mysql报错RSA private key file not found的解决方法

    mysql报错RSA private key file not found的解决方法

    当MySQL报错RSA private key file not found时,可能是由于MySQL的RSA私钥文件丢失或者损坏导致的,此时可以重新生成RSA私钥文件,以解决这个问题
    2023-06-06

最新评论