1、执行mysql -u root -p指令

2、执行命令vim /etc/my.cnf,添加语句skip-grant-tables
3、执行该命令service mysqld restart。

4、无需密码,直接登录。

5、使用数据库,查看数据表。

6、修改密码
update user set authentication_string=password("root") where user='root';

7、执行刷新操作!!!
flush privileges;

8、执行mysql -u root -p命令,输入密码,登入成功!!!

9、注销操作,执行命令vim /etc/my.cnf
