1、修改 /etc/my.cnf 配置文件
vim /etc/my.cnf 添加 skip-grant-tables
2、重启mysql服务
service mysqld restart
3、输入用户,直接回车进去
4、进入mysql数据库
5、修改密码
update user set authentication_string=password("new password") WHERE user='root' ' and host = 'localhost';
6、去除第一步中的配置 skip-grant-tables,重启mysql服务就好了