MySQL重置root密码方法

Windows:

1.win+R,运行里输入services.msc打开服务,关闭MySQL57服务(57是我的MySQL Server的版本号)

MySQL重置root密码方法

2.win+R。运行中输入cmd,cd D:/Appserv/MySQL//bin回车进入bin目录下面,

MySQL重置root密码方法

3.输入:mysqld --defaults-file="D:/Appserv/MySQL/my.ini"  --skip-grant-tables  跳过权限安全检查,开启mysql服务,这样连接mysql时,可以不用输入用户密码

MySQL重置root密码方法

4.win+R,新开一个cmd窗口,原来的别关了呀。

MySQL重置root密码方法

5.输入mysql  -uroot -p,如果出现Enter passwrod:直接回车就能进去

MySQL重置root密码方法

6.如果不想改密码,只是想看原来的密码的话。可以在命令行执行这个语句

select host,user,password from mysql.user;//即可查看到用户和密码(加密后的)

 注:mysql 5.7以后password 不存在了改为authentication_string 

MySQL重置root密码方法

7.如果要修改密码的话,在命令行下执行下面的语句

update mysql.user set password=PASSWORD('新密码') where User='root'; 

update mysql.user set authentication_string =PASSWORD('新密码') where User='root'; //5.7以后版本


8.如果表中密码过期,密码过期状态(password_expired字段值)是否为Y,Y表示已过期,需要修改为N

select host,user,authentication_string,password_expired  from user;

如果为Y则会导致Navicat for MySQL出现错误

1862错误:Your password has expired. To log in you must change it using a client that supports expired.

9.exit退出mysql,关闭cmd窗口


10.在任务管理器中关闭mysqld.exe;

MySQL重置root密码方法
11.重启服务