step1:在my.ini配置檔案中加入選項,以跳過密碼驗證:
skip-grant-tables
shared-memory:
step2:重新開機mysqld服務,以使新增配置項生效
step3:在指令行中使用mysql無密碼方式登入:
> mysql -u root # 直接回車即可,如果跟了-p,出現輸入密碼時直接回車即可跳過
step4:将root密碼置空
> update user set authentication_string = null where user = 'root';
> flush privileges;
step5:exit退出mysql
step6:将my.ini配置檔案中step1中加入的選項注釋掉,并重新開機mysqld服務
step7:mysql -u root進入mysql指令行模式,此處密碼為空
step8:alter user 'root'@'localhost' identified with caching_sha2_password BY 'Alpha_123456';
如此,則root的密碼被修改成功,可以重新登入了。
注意:新密碼要求需包括大寫字母、小寫字母、特殊字元,缺一不可。