1、mysql的版本为5.7.16
2、编辑配置文件/etc/my.cnf加入内容skip-grant-tables
3、重启mysql服务,生产环境中慎用
4、直接使用mysql命令进行登录select Host,User,authentication_string from users;每个mysql的版本不相同,最好能查看下密码、用户存放的字段,不知道具体字段可以使用desc先查看mysql表结构
5、更新密码u衡痕贤伎se mysql;update user set authentication_string="123456" where Host='localhost' and User='root';
6、去掉或者注释/etc/my.cnf中的skip-grant-tables
7、再次重启mysql服务