Environment: Alma Linux 8.2
( CentOS
alternative derivative of ),MySQL 5.7.x
When changing the password, an error will be reported:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
The main reason for the problem is that MySQL
there is a default password policy:
- Contains at least 1 case
- Contains at least 1 digit
- Contains 1 special symbol
- Must be 8 digits or more
If you don't want to set the password so complicated, you need to modify the default password policy.
In MySQL 5.7
, you can enhance the security of the database by modifying the password policy parameters. Following are MySQL 5.7
the steps to modify password policy in .
[Note] To modify MySQL 8.0
the password policy of , please move to: Solve the MySQL 8.0 modification password error: Your password does not satisfy the current policy requirements.
1. Connect to the MySQL server:
mysql -u root -p
Enter root
the user's password to log in.
2. View the current password policy:
SHOW VARIABLES LIKE 'validate_password%';
3. Modify the following variables according to your needs:
-
validate_password_policy
: password policy, the default value isMEDIUM
. Can be set toLOW
,MEDIUM
,STRONG
or custom. For example, set it toLOW
reduce password complexity requirements.SET GLOBAL validate_password_policy = LOW;
Requirements of different strategies:
0/LOW
: only verify the length;
1/MEDIUM
: verify the length, number, case, special characters; the default value.
2/STRONG
: Verify length, number, case, special characters, dictionary file; -
validate_password_length
: The minimum password length, the default value is8
. Modify the minimum password length as needed.SET GLOBAL validate_password_length = 6;
-
validate_password_number_count
: The number required in the password, the default is1
. Number requirements can be increased or decreased.SET GLOBAL validate_password_number_count = 1;
-
validate_password_special_char_count
: Requirements for special characters in passwords, the default is1
. Special character requirements can be increased or decreased.
SET GLOBAL validate_password_special_char_count = 1;
validate_password_mixed_case_count
: Requirements for uppercase and lowercase letters in passwords, the default value is1
. The uppercase and lowercase requirements can be increased or decreased.SET GLOBAL validate_password_mixed_case_count = 1;
4. Modify the configuration file to make the modified password policy permanent.
Open MySQL
the configuration file (usually my.cnf
or my.ini
), add the following to the file:
validate_password_policy=LOW
validate_password_length=6
validate_password_number_count=1
validate_password_special_char_count=1
validate_password_mixed_case_count=1
5. Restart the MySQL service to apply the changes:
sudo systemctl restart mysql
After completing the above steps, MySQL 5.7
the password policy for has been modified. You can adjust the parameters of the password policy as needed, and ensure that an appropriate password policy is set to improve the security of the database.