以Community Server安裝方式的mysql 修改初始密碼記錄
最近開始學習mysql的學習使用,困擾了很久。找了很多方法,都木有效果,今天嘗試一下,居然成功了。
一、之前用的方式:
在my.ini檔案末尾加上“skip-grant-tables”(取消許可權設定)儲存檔案
重啟mysql服務
cmd下進入mysql - bin目錄,輸入 mysql -u root -p ,回車,這時候不需要密碼即可登入
重置密碼。輸入 use mysql 回車
輸入update user set authentication_string=password("newPassword") where user="root"; (新版本下mysql資料庫password欄位更改為authentication_string)
刪除my.ini檔案末尾“ skip-grant-tables”儲存檔案
重啟mysql服務,就可以用新密碼登入root賬戶
然後並沒有生效(>O<),不知道為啥。(預設密碼為空,需要按Enter鍵。可能沒有重啟電腦)
二、重試成功後的方法
- 直接以管理員身份執行cmd,進入bin資料夾下,啟動mysql:mysql -u root
執行命令:SET PASSWORD FOR 'root'@'localhost' = PASSWORD<'newword'>;
2. 用mysqladmin將root賬號已經設定過密碼後,設定新密碼,則執行mysqladmin -u root password "newpass"
mysqladmin -u root password "newpass"
如果root已經設定過密碼,採用如下方法
mysqladmin -u root password oldpass "newpass"
【結果】本人在執行方法1後,執行命令2更新密碼失敗,退出後重新啟動,執行:mysql -u root 報1045錯誤
於是,關閉當前cmd,重新以管理員身份進入mysql安裝目錄下的bin檔案,並執行:mysql -u root -p
執行成功,並輸入第一次設定的密碼。
3. 使用update mysql.user set authtntication_string=password<'root'> where user='root'; 報錯了,目前還沒有找到解決辦法,後續再跟。(┭┮﹏┭┮)