解决忘记mysql密码的方法

在linux下:

查看Mysql进程:ps -ef|grep mysqld

如果Mysql正在运行,首先杀之:killall -TERM mysqld;

启动Mysql:bin/mysqld_safe --skip-grant-tables &

就可以不需要密码就进入了Mysql了。

然后就是

>use mysql

>update user set password=password("new_pwd") where user="root";

>flush privileges;

重新杀Mysql,用正常方法启动。

在window下:

打开命令窗口,停止mysql服务:

net stop Mysql

启动Mysql:一般到Mysql的bin安装目录,找到mysqld.exe

执行:Mysqld.exe --skip-grant-tables当前窗口将会停止。

另外打开一个命令行窗口,执行Mysql(如果提示没有这个命令,先进入Mysql的bin安装目录,再运行Mysql)

>use mysql

>update user set password=password("new_pwd") where user="root";

>flush privileges;

>exit

重启Mysql服务,就可以用新密码登录了。

原文地址:https://www.cnblogs.com/hyzhou/p/2295528.html