MySQL5.7版本初始密码及密码策略修改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='A';
3、但是基于密码策略,所修改的密码必须要包含⼤⼩写字母、数字和字符。通过show命令查看当前的策略
mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
root的初始密码| 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 LOW Length
1 or MEDIUM Length; 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)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。