本人沒有保管號自己mysql的密碼,致使無法登陸上,搜尋了一下午,一無所獲,后來在一片博客中發現網上的都是8.0以前的版本所以不能使用與自己的8.0版本,安裝博主的步驟自己試了試,可以運行。
希望能夠幫助自己和朋友們少走彎路
0.修改my.ini 文件在【mysqld】段下面加入skip-grant-tables,並關閉mysql服務
1.使用cd指令切換到mysql的bin目錄
2.使用mysqld --defaults-file=" my.ini配置文件的路徑" -console -skip-grant-tables這時系統如下圖。之后的步驟與8.0之前的版本完全相同。但是為了加強記憶我在寫一遍。
3.再打開一個命令行,轉到mysqlbin目錄下輸入mysql
4.使用show database查看所有數據庫
5.使用 use 【數據庫名】指令打開指定的數據庫,這是系統回復 database changed
6.這是可以使用指令select user,host,authentication_string from user 觀看數據庫密碼
7.輸入flush privileges否則會出現錯誤
ERROR 1290 (HY000): The MySQL server
is
running with the --skip-grant-tables option so it cannot execute
this
statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY
'123'
WITH GRANT OPTION;
ERROR 1290 (HY000): The MySQL server
is
running with the --skip-grant-tables option so it cannot execute
this
statement
8. 使用ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';修改密碼,注意新密碼的格式為 大寫字母+小寫字母+特殊符號+數字否則密碼不生效
有些博客采用update user set authentication_string='12345' where user='root' ;來修改密碼,我試過,沒用。當然有的博客上說如果authentication_string下有值則需用
update user set authentication_string='' where user='root' ;先清除一下authentication_string。這個我還沒有測試。
注意密碼字段在數據庫中的名字為authentication_string不是password另外語句最后的分號不能,而且password()函數再高版本也不能用了。
9.最后可以使用quit離開數據庫
如果出現了數據庫顯示正在運行,這個不用管,這是my.ini加入skip-grant-tables的原因造成的
如果提示無法打開數據庫那么可以先刪除mysql安裝目錄下的data文件夾,然后在cmd下重新初始化數據庫