MySQL5.7版本初始密码及密码策略修改

本文介绍了MySQL5.7安装后如何修改root用户的初始密码,并详细讲解了密码策略,包括validate_password_policy、validate_password_length等参数。通过调整策略,降低安全级别以满足最低密码要求。

1、初始安装的mysql数据库默认设置了root用户密码,必须要修改密码之后才能够使用。

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

2、先通过grep查找获取root密码,进入数据库修改初始密码。

[root@host54 opt]# grep password /var/log/mysqld.log 
2018-07-17T11:40:19.847141Z 1 [Note] A temporary password is generated for root@localhost: 2wieko:N1(,#
[root@host54 opt]# mysql -uroot -p'2wieko:N1(,#'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17

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> set  password  password='123qqq...A';

3、但是基于密码策略,所修改的密码必须要包含大小写字母、数字和字符。通过show命令查看当前的策略

mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

1) validate_password_policy:密码安全策略,默认MEDIUM策略

策略  检查规则
0 or LOWLength
1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

2)validate_password_dictionary_file:密码策略文件,策略为STRONG才需要

3)validate_password_length:密码最少长度

4)validate_password_mixed_case_count:大小写字符长度,至少1个

5)validate_password_number_count :数字至少1个  

6)validate_password_special_char_count:特殊字符至少1个

4、修改策略(将策略要求置为LOW,长度要求置为1)

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

    经测试,最小长度为4,设置1无效,具体原因还不清楚

5、修改密码成功

mysql> alter user 'root'@'localhost' identified by '1234';
Query OK, 0 rows affected (0.00 sec)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值