mysql8.0.18忘记密码
方法一
-
管理员身份进入dos
-
停止mysql服务
net stop mysql
-
无密码启动
C:\Windows\System32>D:\mysql-8.0.18-winx64\bin\mysqld --console --skip-grant-tables --shared-memory
-
另启一个dos窗口,无密码登录
C:\Windows\System32>D:\mysql-8.0.18-winx64\bin\mysql -u root
-
清空密码
注意:authentication_string采用的是plugin加密方式,故设置为空,不要设置为其他值
mysql> UPDATE mysql.user SET authentication_string=’’ WHERE user=‘root’;
-
启动服务
关闭打开的两个dos窗口,然后以管理员身份重新打开一个dos窗口,启动服务
net start mysql -
无密码登录
C:\Windows\System32>D:\mysql-8.0.18-winx64\bin\mysql -u root -
重新设置密码
alter user root@localhost identified by ’root’; -
新密码登录
C:\Windows\System32>D:\mysql-8.0.18-winx64\bin\mysql -u root -proot
方法二
-
停掉mysql服务
-
在mysql.ini下,添加“skip-grant-tables”配置(mysqld这样可以去掉登录时的密码验证)
-
重启mysql
-
在cmd下输入mysql -uroot -P3306 ,无密码登录
-
use mysql;
-
set password=password(‘123’) --error
update user set password=password(‘admin’) where user=‘root’ and host=‘localhost’;
- 重启,或直接flush privileges;