MySQL8忘记密码重置

一、以管理员身份打开cmd,停止mysql(Windows)

net stop mysql

二、无密码启动

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

 

 三、登录mysql(再重新打开一个窗口)

mysql.exe -u root

 

 四、清空密码

UPDATE mysql.user SET authentication_string='' WHERE user='root' and host='localhost';

五、修改密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';

六、如果报错

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

七、执行

flush privileges;

八、再修改一次

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';

 

 九、登录,输入密码

 

mysql -u root -p

 

十、linux重置密码

修改文件
vi /etc/my.cnf
在mysqld下面添加skip-grant-tables
如下图

 

 十一、重启mysql后登录

停止
systemctl stop mysql.service
启动
systemctl start mysql.service
登录
mysql -u root -p
提示输入密码,直接回车

十二、清空mysql的密码

use mysql;
update user set authentication_string = '' where user = 'root';
清空了密码退出
quit;

十三、删除一开始设置的skip-grant-tables,重启mysql

十四、进入mysql重新设置密码(密码太简单了会报错)

use mysql;
ALTER USER 'root'@'%' IDENTIFIED BY '密码';
quit;

 

 

 

 

posted @ 2021-09-09 15:58  ki1616  阅读(418)  评论(0编辑  收藏  举报