mysql忘记登录密码解决方法

报错情况如下:
[[email protected] ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
解决方法:
编辑配置文件:
vim /etc/my.cnf
在最后一行添加skip-grant-tables
如图:
mysql忘记登录密码解决方法
2.systemctl restart mysqld 重启mysql服务
mysql> update user set authentication_string=password(‘123456’) where user=‘root’; 注意用手打出错的可能性更小。
mysql> flush privileges;
然后使用命令:mysql -uroot -p123456就能登录。