Fonzi

 

【MySQL】window中MySQL8.0以上重置密码

window中MySQL8.0以上重置密码

1.免密码登录MySQL

1.1.使用管理员打开cmd

image

1.2.关闭MySQL服务

net stop mysql 

1.3.输入MySQL免密登录命令

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

image

不要关闭这个窗口!!!

2.开放远程链接

2.1.打开一个新的cmd窗口

2.2.登录MySQL

mysql -u root -p
//提示输入密码的时候直接回车

image

2.3.切换数据库

use mysql;

2.4.查看user下host配置

select user,host from user;

image

如root中的host不为%,需改为%

//修改root用户的host字段
update user set host="%" where user="root";

//使本次修改立即生效
flush privileges;

//退出
quit

3.修改密码

3.1.清空密码

//登录
mysql -u root -p
//无需输入密码,直接回车
//一行行输入命令
use mysql
update user set authentication_string='' where user='root';
quit

image

3.2.将第一个cmd窗口关闭

image

3.3.启动MySQL

net start mysql 

3.4.密码之前已清空,直接免密码登录

mysql -u root -p//无需输入密码,直接回车

3.5.修改密码

alter user 'root'@'%' identified by '新密码'; //退出quit

image

4.检验密码是否修改成功

mysql -u root -p//输入刚刚修改的密码

image

成功!!

posted on 2021-11-11 22:52  Fonzi  阅读(128)  评论(0)    收藏  举报

导航