mysql5.7重置root密碼的步驟詳解

本篇文章給大家?guī)?lái)的內(nèi)容是關(guān)于mysql5.7重置root密碼的步驟詳解,有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)你有所幫助。

安裝完mysql5.7后忘記了密碼,需要重置root密碼;

第一步:修改配置文件免密碼登錄mysql

vim /etc/my.cnf   ##在my.cnf的[mysqld]字段加入 skip-grant-tables  ## 重啟mysql服務(wù) service mysqld restart

第二步:免密碼登錄mysql

mysql -u root  ##password直接回車

第三步: 給root重置密碼為空

mysql>use mysql; ## mysql 5.7.9以后廢棄了password字段,字段名修改為authentication_string mysql>update user set authentication_string='' where user='root'; ## 刷新數(shù)據(jù)庫(kù) mysql>flush privileges;

第四步: root重置密碼
??退出mysql,刪除/etc/my.cnf文件最后的 skip-grant-tables 重啟mysql服務(wù),使用root用戶進(jìn)行登錄,因?yàn)樯厦嬖O(shè)置了authentication_string為空,所以可以免密碼登錄。

alter user 'root'@'localhost' identified by '#新密碼#';

功德圓滿,修改成功

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊10 分享