今天剛裝上 MySQL 設置完成密碼,結果轉頭密碼就忘了。不得已,只好跳過密碼驗證然后再登錄之后修改密碼
首先找到 MySQL 的配置文件:/ect/my.cnf(windows 下的 MySQL 配置文件是在 MySQL 的安裝目錄下的 my.ini 文件中,在[mysqld]下添加 skip-grant-tables)
加上:skip-grant-tables (請看下圖)保存之后重啟 MySQL 服務,再次登錄的時候就直接 mysql 就可以登錄上(默認是 root 用戶)
或者直接用 mysqld_safe -skip-grant-tables & 命令也可以跳過 MySQL 的登錄檢查
【linux】
【windows】
然后就是修改密碼了
use mysql; update user set password=password('root') where user='root';