MySQL忘记密码

如下

1、先停止服务
service mysqld stop     停止

2、修改配置
linux修改命令:vi /etc/my.cnf
windows系统是my.ini文件手动添加
在文件最后加上:skip-grant-tables

3、重启服务
service mysqld start    启动

4、输入命令:mysql,回车,进入mysql执行窗口,或者输入:mysql -uroot -p ,点击回车

5、输入:use mysql;

6、输入:alter user root identified by 'xxx';
注意,如果此时报错:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

可执行:flush privileges;然后再执行修改密码命令就好了

7、如果报:Operation ALTER USER failed for ‘root‘@‘%‘;

可修改user表中的Host: update user set Host='%' where User='root';   
说明: % 代表任意的客户端,可替换成具体IP地址
修改密码命令也可以用:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxx';
这样其他电脑也可以远程访问该数据库了; 8、如果密码强度不够,会提示: Your password does not satisfy the current policy requirements 重新调整密码强度即可 9、flush privileges; 10、vi /etc/my.cnf,将文件最后方添加的:skip-grant-tables,删除; 11、重启服务:service mysqld restart;
end;
posted @ 2023-05-12 11:16  xh_Blog  阅读(38)  评论(0)    收藏  举报