Mysql忘记密码操作

mysql忘记密码了,在网上找了许久,终于找到能行的了

1.终止MySql服务

右键-管理-服务-MySql-停止服务

或者

以管理员身份打开cmd,执行:

net stop mysql

2.跳过密码输入授权

 mysqld --console --skip-grant-tables --shared-memory 

3. 重新打开一个cmd窗口(刚才的cmd窗口不要关),重置密码,执行:

mysql -uroot -p

这时已经绕过密码登录mysql了。 

修改密码,将密码置为空

UPDATE mysql.user SET authentication_string='' WHERE user='root';

4.关闭所有命令行界面,正常开启MySql服务后进行登录(当要数据密码时,按回车即可)

use mysql 

#设置密码为123456

ALTER user root@'localhost' identified by '123456';

或者可以

设置加密规则并更新新密码,授权(直接复制这些SQL语句你的密码会更新为123456)

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; 
alter user 'root'@'localhost' identified by '123456';
grant all privileges  on *.*  to "root"@'localhost';
flush privileges;

5.密码设置成功,重启mysql,使用新密码登录

net start mysql

猜你喜欢

转载自blog.csdn.net/weixin_69884785/article/details/134819285