windows和linux下mysql忘记root密码的解决方法

windows

1.在DOS窗口下输入net stop mysql 停掉服务器(或者通过进程)

2.mysqld --skip-grant-tables;

3。

update mysql.user set authentication_string=password('root') where user='root' ;

update user set password_expired='N' where user='root';

flush privileges;

quit

4.重新登录

linux 

 vi  /etc/my.cnf 

[mysqld]下面加上 skip-grant-tables 

mysql -uroot -p

mysql> use mysql; 
mysql> update user set password=password('123') where user='root'; 
mysql> flush privileges; 

退出mysql

删除skip-grant-tables

重启mysql,完成。

猜你喜欢

转载自blog.csdn.net/weixin_41934671/article/details/86164833
今日推荐