当root用户,忘记了密码。可以使用破解的方式来登录系统。修改密码。
修改mysql启动设置 免密登录mysql
# vim /etc/my.cnf
重启mysql并登录
# systemctl restart mysqld
# mysql -uroot
update修改自己的密码
mysql> update mysql.user set authentication_string=password('Xuan@123') where user='root' a
nd host='localhost';
刷新数据库
mysql> flush privileges;
\q 退出
修改完MySQL密码
将配置文件中的跳过密码的命令注释
vim/etc/my.cnf
用修改过的密码进行登录mysql
#mysql -uroot -pXuan@123
完成,可以正常使用数据库了。