MySQL 8.0.28 忘记密码,重置密码
- 1.管理员权限打开CMD窗口,cd到mysql安装目录的bin文件夹下
然后输入net stop mysql停止mysql服务
- 2.输入mysqld --console --skip-grant-tables --shared-memory跳过Mysql的密码认证
- 3.重新用管理员权限打开一个新的cmd窗口,cd到mysql安装目录的bin文件夹下之后,输入mysql -u root -p无密码登录.注意,之前打开的cmd窗口不能关闭
- 4.将登录密码设置为空字符串
use mysql;
-- 将root用户的密码置为空
update user set authentication_string = '' where user = 'root';
quit;
- 5.将这个窗口关闭
- 6.输入net start mysql打开mysql服务,然后输入输入mysql -u root -p无密码登录
- 7.修改密码
use mysql;
-- 查询root用户的host
select user,host from user where user = 'root';
-- 修改密码
ALTER USER 'root'@'%' IDENTIFIED BY '新密码';
-- 刷新权限
flush privileges;
-- 退出登录
quit;
- 8.登录测试,登录成功!