首頁  >  文章  >  資料庫  >  mysql5.7重設root密碼的步驟詳解

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

不言
不言轉載
2019-01-23 11:14:464692瀏覽

這篇文章帶給大家的內容是關於mysql5.7重置root密碼的步驟詳解,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。

安裝完mysql5.7後忘了密碼,需要重設root密碼;

#第一步:修改設定檔免密碼登入mysql

vim /etc/my.cnf  
##在my.cnf的[mysqld]字段加入
skip-grant-tables

## 重启mysql服务
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';
## 刷新数据库
mysql>flush privileges;

#第四步: root重置密碼
  退出mysql,刪除/etc/my.cnf檔案最後的skip-grant-tables 重啟mysql服務,使用root用戶進行登錄,因為上面設定了authentication_string為空,所以可以免密碼登入。

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

功德圓滿,修改成功

#

以上是mysql5.7重設root密碼的步驟詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:segmentfault.com。如有侵權,請聯絡admin@php.cn刪除