首先要停止服务:systemctl stop mysqld
接下来通过忽略mysql授权表的方式启动数据库服务,启动服务后,修改密码。
在/etc/my.cnf配置文件中。增行如下:
[mysqld]
skip-grant-tables;
修改完成后,重启mysql服务,使用空密码登陆。
然后使用以下方法修改密码:
mysql> update user set password = PASSWORD('123456') where user = 'root';
注意:mysql5.7已经没有password字段了,改为:authentication_string 了
mysql> update user set authentication_string = PASSWORD('123456') where user = 'root';flush privileges;