1、mysql服务正常运行ps -ef|grep mysql

2、登录的时候报root密码错误ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

3、vi /etc/my.cnf,在[mysqld]下面加入skip-grant-tables

4、重启mysql服务systemctl restart mysqld

5、不需要密码直接使用mysql即可登录

6、切换到系统库use mysql

7、查找系统库中用户的表名show tables;

8、查看user的表结构,分析出密码字段名称desc userauthentication_string

9、mysql> update user set authentication_string=password("haha") where user="root"; Query OK, 1 row affected, 1 warning (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 1mysql> flush privileges;Query OK, 0 rows affected (0.01 sec)
10、vi /etc/my.cnf,在[mysqld]下面去掉skip-grant-tables并重启mysqld服务

11、使用修改后的密码进行登录验证mysql -uroot -phaha
