原文章位址: https://blog.csdn.net/qq_35202206/article/details/81092430此文章是自己修改後,重新寫的一篇文章 如果覺得不夠詳細可以參考上面的位址。
修改前建議建立快照 ,以防錯誤修改 導緻系統無法啟動
下面操作是centos 7.6版本的,mysql是5.7 其他版本可以參考下。
- 今天一上線,哎呀密碼忘記了。不知道怎麼搞,這是密碼錯誤的截圖
linux mysql資料庫忘記密碼怎麼找回密碼? - 輸入下面的指令
vi /etc/my.cnf
- 出現下面的圖
linux mysql資料庫忘記密碼怎麼找回密碼? - 接着按 i 鍵,出現圖檔中的INSERT,就可以正常修改了。不按無法修改
linux mysql資料庫忘記密碼怎麼找回密碼? - 在[mysqld]添加一行 skip-grant-tables
linux mysql資料庫忘記密碼怎麼找回密碼? - 然後按ESC鍵,INSERT不再出現了。然後按 shift鍵 + :鍵,輸入wq! 回車
linux mysql資料庫忘記密碼怎麼找回密碼? - 重新開機mysql
systemctl restart mysqld
- 然後輸入mysql 可以直接進去
linux mysql資料庫忘記密碼怎麼找回密碼? - 修改root密碼,輸入下面指令
update mysql.user set authentication_string=password('123456789sW!') where user='root' ;
- 退出mysql 輸入exit 退回桌面後 重新開機mysql
systemctl restart mysqld
-
删掉上面的 skip-grant-tables
輸入
,找到 skip-grant-tables 删掉 然後按照上面的方法儲存wq!vi /etc/my.cnf
-
systemctl restart mysqld
- 回到桌面後 輸入mysql -uroot -p123456789sW!
linux mysql資料庫忘記密碼怎麼找回密碼? - 修改成功了。如果不懂可以參考原創的文章