修改配置文件/etc/my.cnf
[mysqld]
skip-grant-tables #跳过授权表
然后直接敲命令就能进
[root@localhost ~]# mysql //无需使用账号及密码
mysql> alter user 'root'@'localhost' identified by '123456'; //报错后刷新授权表
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
修改完密码记得删除开始添加的内容