mysql安装了时间太久没有使用,突然要使用了忘记密码了怎么办?
我们要先关闭mysql服务。
关闭的方法:
2.1 此电脑》右键》管理

2.2 服务和应用程序?服务

2.3找到myslq服务,然后右键停止服务

2.4cmd打开黑窗口
输入:
输入mysqld --console --skip-grant-tables --shared-memory 命令。–skip-grant-tables 会让 MySQL 服务器跳过验证步骤,允许所有用户以匿名的方式,无需做密码验证就可以直接登录 MySQL 服务器,并且拥有所有的操作权限。
mysqld --console --skip-grant-tables --shared-memory

切记这个黑窗口不要关闭!!!!
然后另外启动一个黑窗口,直接输入命令 mysql -uroot -p 密码随便输入
mysql -uroot -p

输入修改密码命令:
如果是以前的MySQL版本,常使用password函数来进行修改密码:密码是123456
update mysql.user set password=password('123456') where user='root';
update mysql.user set password=password('123456') where user='root';
但是MySQL8之后,没有了password字段和password()函数,所以不能使用上面的修改密码的方法。
使用以下命令进行修改:密码是123456
alter user 'root'@'localhost' identified by '123456';
alter user 'root'@'localhost' identified by '123456';
注意:如果出现报错问题请执行以下命令:
flush privileges
flush privileges
若果没有报错也要执行以下命令:
flush privileges
flush privileges
最后:
关闭所有黑窗口,到此电脑》管理》服务》启动mysql服务。然后正常登录即可。
如果有其他问题,可联系博主进行交流。