首次登录mysql,需要修改原始密码。
mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> alter user 'root'@'localhost' identified by "123456";ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql> alter user 'root'@'localhost' identified by "Demo12345!";Query OK, 0 rows affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.00 sec)mysql> select &&basedir -> ;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '&&basedir' at line 1mysql> select @@basedir;+-----------+| @@basedir |+-----------+| /usr/ |+-----------+1 row in set (0.00 sec)
查看密码策略,在mysql> 后输入:
mysql> show variables like 'validate_password%';+--------------------------------------+--------+| Variable_name | Value |+--------------------------------------+--------+| validate_password.check_user_name | ON || 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)
修改指定密码的验证强度等级
mysql> set global validate_password.policy=LOW;Query OK, 0 rows affected (0.00 sec)mysql> show variables like 'validate_password%';+--------------------------------------+-------+| Variable_name | Value |+--------------------------------------+-------+| validate_password.check_user_name | ON || validate_password.dictionary_file | || validate_password.length | 8 || validate_password.mixed_case_count | 1 || validate_password.number_count | 1 || validate_password.policy | LOW || validate_password.special_char_count | 1 |+--------------------------------------+-------+7 rows in set (0.00 sec)
修改指定密码长度
mysql> set global validate_password.length=6;Query OK, 0 rows affected (0.00 sec)
标题密码策略修改完成后,修改密码为123456
mysql> alter user 'root'@'localhost' identified by '123456';Query OK, 0 rows affected (0.00 sec)mysql>
关于 Mysql 8.0.19 Homebrew 安装版本密码策略相关参数:
validate_password.dictionary_file #指定密码验证的文件路径;validate_password.length #固定密码的总长度,默认为8;validate_password.mixed_case_count #整个密码中至少要包含大/小写字母的总个数;validate_password.number_count #整个密码中至少要包含阿拉伯数字的个数;validate_password.policy #指定密码的强度验证等级,默认为 MEDIUM;validate_password.special_char_count #整个密码中至少要包含特殊字符的个数;
※ 指定密码的强度验证等级validate_password.policy 取值:
0/LOW #只验证长度;1/MEDIUM #验证长度、数字、大小写、特殊字符;2/STRONG #验证长度、数字、大小写、特殊字符、字典文件;
来源地址:https://blog.csdn.net/weixin_44048054/article/details/131657430