Contos7中Mysql忘记密码或者初始登录时密码错误解决方法 Contos7中Mysql忘记密码或者初始登录时密码错误解决方法

Contos7中Mysql忘记密码或者初始登录时密码错误解决方法

1、先停止mysql服务

service mysqld stop

2、修改mysql的配置文件,通过下面命令,进入配置文件当中

vim /etc/my.cnf

在文件末尾加上

skip-grant-tables

3、重启mysql服务,

service mysqld start

4、进入数据库(输入密码时,直接回车即可)

mysql -u root -p

5、重置mysql密码

update mysql.user set password=password('123456') where user='root';

根据版本不同,如果执行上述语句报错,Unkown column “password”in “field list”,原因是新的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string,此时需要将上述语句改为如下所示 :

update mysql.user set authentication_string=password('123456') where user='root'and host='localhost';

6、密码改成功后,需将skip-grant-tables给删除掉。
vim /etc/my.cnf 进行删除

7、重启mysql服务

service mysqld restart

8、输入密码,正常登录mysql即可

作者:山乀原文地址:https://blog.csdn.net/weixin_45942827/article/details/128045571

%s 个评论

要回复文章请先登录注册