1、如下是Windows操做系統的操做步驟:java
1. 關閉正在運行的MySQL服務-->net stop mysql
mysql
2. 打開DOS窗口,轉到mysql\bin目錄。sql
3. 輸入mysqld --console --skip-grant-tables --shared-memory 回車。--skip-grant-tables
的意思是啓動MySQL服務的時候跳過權限表認證,注意skip前面是兩個「-」 ,此時DOS窗口沒法輸入數據庫
4. 再開一個DOS窗口,轉到mysql\bin目錄。ide
5. 輸入mysql回車,若是成功,將出現MySQL提示符 >。加密
6. 鏈接權限數據庫: use mysql; 。操作系統
7. 改密碼:code
update mysql.user set authentication_string=(
"root"
) where user=
'root'
;
ip
出現以下信息表示修改爲功;string
mysql> update mysql.user set authentication_string='root' where user='root';
Query OK, 1 row affected (0.52 sec)
Rows matched: 1 Changed: 1 Warnings: 0
8. 刷新權限(必須步驟):flush privileges;
---修改密碼MySQL版本大於8.0時候(錯誤號碼2059 )
將用戶的加密方式改成mysql_native_password。並修改密碼
alter user 'root'@'localhost' identified with mysql_native_password by '1q2w3e'; -