Mysql 5.7 忘记密码或重置密码

在Centos中安装完MySQL数据库以后,不知道密码,这可怎么办,下面给大家说一下怎么重置密码

1、修改配置文件my.cnf 

在[mysqld]中添加

skip-grant-tables

然后重启mysql


登录mysql

mysql -uroot -p

直接回车

选择数据库

use mysql;

下面我们就要修改密码了


以前的版本我们用的是以下修改

update user set password=password('root') where user='root';

但是在5.7版本中不存在password字段,所有我们要用以下修改进行重置密码update user set authentication_string=password('123456') where user='root';

flush privileges;

下一篇: 没有了