windows修改mysql5.7密碼(解決:Access denied for user 'root'@'localhost' (using password:YES))

目的:修改mysql密碼

步驟:

1、打開MySQL目錄下的my.ini文件,在文件的最後添加一行“skip-grant-tables”,保存並關閉文件。(WIN7默認安裝,my.ini在C:\ProgramData\MySQL\MySQL Server 5.7)

1

2、重啓MySQL服務。

3、通過命令行進入MySQL的BIN目錄,輸入“mysql -u root -p”(不輸入密碼),提示輸入密碼,直接Enter回車即可進入數據庫。(WIN7默認安裝,BIN目錄爲:C:\Program Files\MySQL\MySQL Server 5.7\bin)

4、執行“use mysql;”,使用mysql數據庫。

5、update user set authentication_string=password('root') where user='root';

注意:mysql5.7以下的版本,沒有authentication_string這個字段,要使用password字段,如下:

update user set password=password("root") where user='root'

6、打開MySQL目錄下的my.ini文件,刪除最後一行的“skip-grant-tables”,保存並關閉文件。
7、重啓MySQL服務,至此密碼修改成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章