-
使用管理員權限打開cmd (搜索cmd, 右鍵點擊"使用管理員身份運行")
-
命令列輸入
net stop mysql;運行后提示為
MySQL 服務正在停止. MySQL 服務已成功停止, -
mysqld –skip-grant-tables實測在mysql8.0中已失效, 現在使用另一個指令:mysqld --console --skip-grant-tables --shared-memory -
另外打開一個cmd, 此時使用mysql可以無密碼登錄了
mysql -u root -
8.0版本不允許在跳過策略 skip-grant-tables 時修改密碼, 所以要先清空root用戶的密碼
update user set authentication_string = '' where user = 'root'; -
然后通過空密碼正常訪問資料庫
mysql -u root -p -
進入MySQL系統自帶資料庫: mysql資料庫中, 執行更改密碼陳述句
mysql> use mysql; mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新的密碼';mysql5.7以前的版本用 update user set password=password("新的密碼") where user="root";
-
重繪權限后, 退出MySQL
mysql> flush privileges; mysql> exit;
然后就可以使用新的密碼登錄資料庫了
錯誤處理
can't connect to mysql server on 'localhost'
windows 主機:
右鍵點擊我的電腦→選單中點擊管理→服務和應用程式→服務→找到MySQL服務, 查看其狀態, 若沒有正在運行, 右鍵點擊該服務, 選擇啟用
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/526934.html
標籤:其他
