MySql教程

MySQL忘记密码解决方案

本文主要是介绍MySQL忘记密码解决方案,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

可以空密码登录的情况

mysql -u root -p

修改随机密码为root

mysql>
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
flush privileges;

无法登陆的情况

1、先修改配置文件 /etc/my.cnf 令MySQL跳过登录时的权限检验,在 [mysqld] 下加入一行:

skip-grant-tables

2、重启MySQL

service mysqld restart

3、免密码登录MySQL。

mysql

4、修改root密码

mysql>  use mysql;
mysql> UPDATE user SET authentication_string = password('新密码') WHERE host = 'localhost' AND user = 'root';
mysql> select host,user, authentication_string, password_expired from user; 
mysql> update user set password_expired='N' where password_expired='Y' //密码不过期
mysql> update user set host='%' where user='root' and host='localhost'; //远程可访问
mysql> flush privileges; //刷新权限
mysql> exit;//退出

5、修改配置文件 /etc/my.cnf 删除此前新增那一行 skip-grant-tables ,并重启MySQL(这一步非常重要,不执行可能导致严重的安全问题)

service mysqld restart //重启 Mysql

参考:

https://help.aliyun.com/document_detail/42520.html

错误排查

输入下面的命令然后查看日志

mysqld --console

添加链接授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
这篇关于MySQL忘记密码解决方案的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!