美文网首页
Linux Mysql 8.0.21忘记密码怎么处理?

Linux Mysql 8.0.21忘记密码怎么处理?

作者: zhimin_ | 来源:发表于2021-07-14 00:59 被阅读0次

1.停掉mysqld进程,修改配置文件后绕过权限校验启动
停掉服务:
service mysqld stop
修改配置文件:
vim /etc/my.cnf[mysqld]下添加skip-grant-tables
启动服务:
service mysqld start

2.登录msyql,并修改密码
登录mysql:
mysql -uroot
修改密码:
alter user 'root'@'%' identified with mysql_native_password by '新密码';
flush privileges;
该操作成功后,表示root用户可以使用新密码远程连接数据库

3.去除配置文件中的skip-grant-tables,重新启动mysql


第三步可能遇到的问题
1.执行alter语句时,如下错,意思是密码太简单了,不符合规则

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

2.查看规则
show variables like 'validate_password%';

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)

上述变量含义如下

validate_password_dictionary_file
插件用于验证密码强度的字典文件路径。
validate_password_length
密码最小长度,参数默认为8,它有最小值的限制,最小值为:validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
validate_password_mixed_case_count
密码至少要包含的小写字母个数和大写字母个数。
validate_password_number_count
密码至少要包含的数字个数。
validate_password_policy
密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
validate_password_special_char_count
密码至少要包含的特殊字符数。

3.按照规则设置密码,或者修改规则
修改规则set global validate_password.mixed_case_count = 0;表示混合大小写字母个数改为0

4.有的小伙伴会遇到 show variables like 'validate_password%';结果为空,如下

show variables like 'validate_passwrod%';
Empty set (0.00 sec)

引用stackoverflow上的解决方案

This problem has happened because validate_password plugin is by default NOT activated. You can solve by these commands:
mysql> select plugin_name, plugin_status from information_schema.plugins where plugin_name like 'validate%';
Empty set (0.00 sec)
mysql> install plugin validate_password soname 'validate_password.so';
Query OK, 0 rows affected (0.02 sec)
mysql> select plugin_name, plugin_status from information_schema.plugins where plugin_name like 'validate%';
Finally, you will show the following:

+-------------------+---------------+
| plugin_name       | plugin_status |
+-------------------+---------------+
| validate_password | ACTIVE        |
+-------------------+---------------+
1 row in set (0.00 sec)

Then you can run your command:
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). 

相关文章

网友评论

      本文标题:Linux Mysql 8.0.21忘记密码怎么处理?

      本文链接:https://www.haomeiwen.com/subject/mhpepltx.html