MySQL 錯誤【二】: Access denied for user ‘root‘@‘localhost‘ (using password: YES) 解決辦法


注:

  1. 管理員下運行 cmd
  2. bin 目錄下

  1. 在 my.ini 下添加 skip-grant-tables, 可免密登錄
    在這里插入圖片描述

  2. 設置密碼

D:\mysql-5.7.35\bin>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功。

D:\mysql-5.7.35\bin>mysql -u root -p
Enter password:   # 此處直接回車,不輸入密碼
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

host:確定要操作的數據庫在哪台電腦上,比如上圖的localhost代表的是本機,如果要操作的是別人的電腦,就需要輸入其他的IP地址

  1. 注掉 skip-grant-tables
    在這里插入圖片描述
  2. 重啟 MySQL 即可
mysql> exit
Bye

D:\mysql-5.7.35\bin>net stop mysql
MySQL 服務正在停止.
MySQL 服務已成功停止。


D:\mysql-5.7.35\bin>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功。
  1. 回到 Navicat 輸入密碼即成功解決
    在這里插入圖片描述


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM