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 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)