- 1. 在Linux系统中编辑/etc/my.cnf文件,在my.cnf文件的空白处加一句
skip-grant-tables
#加入上句代码后,保存退出,并重启mysql
systemctl restart mysqld
- 2. 无密码登录mysql
- 3. 修改密码
这里必须进入mysql库;才能修改密码。原因是这里的mysql并不是没变,数据库位置是变化的;
UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
- 4. 将 /etc/my.cnf 文件内容改回来
- 5. 修改密码成功