MySQL error "Your password does not satisfy the current policy requirements" when creating a user

MySQL error "Your password does not satisfy the current policy requirements" when creating a user

Insert image description here

MySQL is a popular relational database management system that provides many security features, one of which is password policy. When creating or changing a user password, MySQL checks whether the password complies with the current password policy requirements. If the password does not satisfy the policy requirements, you will receive the error message: "Your password does not satisfy the current policy requirements."

Understand MySQL password policy

MySQL's password policy is designed to improve database security, and it includes the following requirements:

  1. Password length: Password must contain at least the specified length of characters.
  2. Uppercase and lowercase letters: Password must contain uppercase and lowercase letters.
  3. Numbers: Password must contain numbers.
  4. Special characters: The password must contain special characters, such as symbols or punctuation.
  5. Does not contain username: The password cannot contain the same part as the username.

solution

If you encounter the "Your password does not satisfy the current policy requirements" error, here are the steps to resolve it:

  1. Review the password policy : First, understand the requirements of the current MySQL password policy. You can obtain policy information through the following query:
   SHOW VARIABLES LIKE 'validate_password%';

This will display the variables related to the password policy and their current values. Note validate_password_policythe value of the variable, which represents the level of the password policy. Common policy levels include 0, 1, and 2.

  1. Choose a password to meet policy requirements : Depending on the policy level, you can choose a stronger password to meet the requirements. Generally, increasing the length of your passwords and including uppercase and lowercase letters, numbers, and special characters can help you meet policy requirements.

  2. Set a password when creating a user : When creating a user, make sure to set a password that complies with policy requirements. Here is an example of creating a user and setting a password:

   CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';

Please replace newuserand StrongPassword123!with your own username and password.

  1. Change password policy (optional): If needed, you can change MySQL's password policy level. You can change the policy level in one of the following ways:

    • Modify the configuration file to add or modify values my.cnf​​in sections.[mysqld]validate_password_policy

    • Execute the following command directly in MySQL:

      SET GLOBAL validate_password_policy = 0; -- 设置策略级别为0(最宽松的策略)
      
  2. More password policies : MySQL's password policy includes multiple parameters that are used to define password requirements and restrictions to improve database security. The following is a description of each parameter of the MySQL password policy:

    • validate_password_length : This parameter specifies the minimum length of the password. The default value is 8. For example, if you set it to 10, the user's password must contain at least 10 characters.

    • validate_password_number_count : This parameter specifies the number of numbers that must be included in the password. The default value is 1. If set to 2, the password must contain at least two numbers.

    • validate_password_policy : This parameter defines the level of password policy, which can have the following values:

      • 0: Password policy is disabled. The password does not need to meet any requirements.
      • 1: Low-level password policy. Password must contain numbers, letters (upper and lower case), and special characters.
      • 2: Medium-level password policy. The password must contain numbers, letters (upper and lower case), and special characters, and cannot contain the same parts as the username.
    • validate_password_special_char_count : This parameter specifies the number of special characters that must be included in the password. The default value is 1. If set to 2, the password must contain at least two special characters.

    • validate_password_mixed_case_count : This parameter specifies the number of uppercase and lowercase letters that must be included in the password. The default value is 1. If set to 2, the password must contain at least two uppercase letters and two lowercase letters.

    • validate_password_check_user_name : This parameter specifies whether the password is allowed to contain the same part as the username. The default value is ON, which means the password is not allowed to contain the username. If set to OFF, the password can contain part of the username.

  3. Reload the MySQL configuration : If you change your password policy, you need to reload the MySQL configuration for the changes to take effect:

    FLUSH PRIVILEGES;
    
  4. Try creating the user : Now, try creating the user again and you should no longer receive the password policy error message.

in conclusion

Encountering the "Your password does not satisfy the current policy requirements" error when creating a user in MySQL is usually because the password does not meet the password policy requirements of the database. By understanding your password policy, choosing strong passwords, and following the steps above, you can successfully create users and improve the security of your database. But be sure not to sacrifice security and carefully change your password policy levels on a case-by-case basis.

Guess you like

Origin blog.csdn.net/weixin_45626288/article/details/132630965