mysql 忘记root密码解决办法

当前版本:mysql5.7

找到my.cnf 一般在/etc/my.cnf 或 macos /usr/local/etc/my.cnf

在[mysqld] 下加入以下语句:skip-grant-tables

执行mysql -uroot -p ,如果提示输入密码,按回车。然后登入mysql

修改密码

use mysql;
update user set password=PASSWORD('你的密码') where user='root';
###  5.7执行以下语句
### update user set authentication_string=PASSWORD('你的密码')  where user='root';
flush priveleges;

再修改my.cnf 将刚添加的语句去掉。成功!!

发表评论

邮箱地址不会被公开。 必填项已用*标注