MySQL 5.7 How to Modify an root Password
- 2021-07-01 08:23:43
- OfStack
Beginning with MySQL 5.7, many security updates have been added. Old version of the user may have a bit of unaccustomed, here about the 5.7 version of the database password issues.
Versions after 5.7. 6
Versions after 5.7. 6 generate passwords and put them in the log file when starting the database, like this:
[root@centos-linux ~]# cat /var/log/mysqld.log | grep 'password'
2016-07-16T03:07:53.587995Z 1 [Note] A temporary password is generated for root@localhost: 2=s6NZk.t:fz
Then use the password to log in to the database, but you can't do anything, prompting you to change the password first.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
If you change the password here, you will encounter verification, and a simple password will prompt that it does not conform to the rules
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
Because 5.7 introduced an validate_password plug-in to check password strength.
The default values are as follows:
mysql> show variables like 'vali%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| 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 |
+--------------------------------------+--------+
6 rows in set (0.01 sec)
The meaning is as follows:
validate_password_length
# The minimum length of the password, which defaults to 8 .
validate_password_mixed_case_count
# Include at least the number of lowercase or uppercase letters, and the default is 1 .
validate_password_number_count
# The minimum number of numbers to include, the default is 1 .
validate_password_policy
# Strength level, which can be set to 0 , 1 , 2 .
" 0/LOW ": Check length only.
" 1/MEDIUM ": In 0 Check numbers, case and special characters based on grades.
" 2/STRONG ": In 1 Check the special character dictionary file based on the level, here is 1 .
validate_password_special_char_count
# The minimum number of special characters to include, the default is 1 .
Therefore, the initial password is larger than 8 digits, including numbers, upper and lower case letters and special characters.
At the same time, these configurations can be modified to weaken password strength verification.