新版mysql密码重置

本教程适用于密码重置的password字段失效情况。

比较简单,如下:

1、Linux下修改/etc/my.cnf【windows下位置请百度】  找到[mysqld]字段,下面加上 

skip-grant-tables

2、退出保存,在bash里输入

cd /etc    #打开my.cnf文件夹,windows请替换

chmod 664 my.cnf    #因为mysql的安全机制使得无权限的my.cnf失效,这里调高权限
service mysqld restart    #重启mysql服务

3、输入以下命令

 1 mysql -uroot -p
 2 
 3 #接着系统出现enter password,不用管,直接回车
 4 
 5 #下面使用mysql syntax直接修改密码
 6 #不要忘记语句末尾的分号
 7 
 8 use mysql;    #使用mysql数据库
 9 
10 select * from user;    #查看user表内所有数据
11 
12 #然后你会看见有一些列:Host、User、_priv等等,我们需要的是
13 #authentication_string和password_expired
14 
15 #更新密码,注意替换引号内的内容
16 update user set authentication_string=password('your password here') where user='your accountname e.g. root';
17 
18 #调整过期时间为No,不用重启后再次输入,注意替换
19 update user set password_expired='N' where user='your accountname e.g. root'; 

4、为了数据库安全,将my.cnf的‘skip-grant-tables’注释掉

5、重启mysql服务器

service mysqld restart
The END

勉强的猫,编程路上的小学生

欢迎关注我的:
原文地址:https://www.cnblogs.com/wangnig/p/8476868.html