看了很多文章,全是将caching_sha2_password加密改为native什么什么的,简直是为了进入数据库新特性都不用了。
这里给出一个在加密为caching_sha2_password情况下修改密码。
如果你当前还是无法进入数据库的情况下,则新建一个窗口,在mysql服务停止的情况下,输入
mysqld --console --skip-grant-tables --shared-memory;
此后,再开一个窗口,仅使用 mysql -u root 即可免密进入数据库。
然后,选择数据库 mysql,即
use mysql;
可以先看到当前 root 用户的密码加密情况
select authentication_string from user where user = "root";
应该是 caching_sha2_password
我们先将 root 的密码置为空串,即
update user set authentication_string = "" where user = "root";
此后,输入命令(好像也可以不用):flush privileges;
然后 exit 退出数据库,并终止第一个窗口的程序执行,即在第一个窗口按下 ctrl + C
然后再到这个窗口上启动mysql服务,即 net start mysql,然后无密码进入 mysql,即
mysql -u root -p
密码为空即可
此后,选择数据库 mysql,即 select mysql;
键入下述命令
alter user "root"@"localhost" identified by "root";
第二个 root 是你要设置的密码
可以看到,此时 root 的密码开头为$A$005 .... 与其它用户的密码格式一致,故此时密码修改完成,即可使用密码root进入。