1、关闭mysql服务
service mysqld stop
2、找到my.cnf配置文件
whereis my.cnf
3、在[mysqld]标签下添加:skip-grant-tables
vim /etc/my.cnf
4、启动mysql服务
service mysqld start
5、无密码登录mysql,执行下面命令
mysql -u root
6、使用数据库中的mysql库
use mysql;
7、执行sql更新密码,将密码设置为空
update user set authentication_string='' where user='root';
8、刷新
flush privileges;
9、修改成功以后退出
exit
10、停止mysql服务
service mysqld stop
11、去掉my.cnf里面的skip-grant-tables内容
vim /etc/my.cnf
12、启动mysql服务
service mysqld start
13、进行登录,提升输入密码直接enter
mysql -u root -p
14、修改密码(密码不能为简单密码,不然会报错)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ww_123456';
以上就是linux虚拟机中忘记密码修改的操作,如果有报错可以在评论区进行评论;