首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> MySQL 資料庫 >> MySQL 綜合教學

Windows 下 MySQL 連線錯誤 1045 解決:skip-grant-tables 重置密碼圖文教學

     編輯:MySQL 綜合教學

Windows MySQL 1045 錯誤解決:重置 root 密碼

錯誤訊息:Access denied for user 'root'@'localhost' (using password: YES)

步驟總覽

  1. 找到 my.ini(安裝目錄或 C:\ProgramData\MySQL\MySQL Server 5.x\)
  2. [mysqld] 區段加入 skip-grant-tables
  3. 重啟 MySQL 服務(服務管理器或 net stop/start mysql)
  4. CMD 進入 bin 目錄,免密登入 mysql -u root
  5. 重置密碼
  6. 移除 skip-grant-tables 並重啟服務

詳細操作

# 1. 找到 my.ini
# 典型路徑:D:\MySQL\MySQL Server 5.6\my.ini

# 2. 編輯 my.ini
[mysqld]
skip-grant-tables
# 其它配置...

# 3. 重啟服務
net stop mysql
net start mysql

# 4. 免密登入
cd D:\MySQL\MySQL Server 5.6\bin
mysql -u root

# 5. 重置密碼
mysql> USE mysql;
mysql> UPDATE user SET authentication_string=PASSWORD('NewPass123!') WHERE user='root';
mysql> FLUSH PRIVILEGES;
mysql> QUIT;

# 6. 移除 skip-grant-tables 並重啟
# 編輯 my.ini 註釋或刪除該行
net stop mysql
net start mysql

# 7. 正常登入驗證
mysql -u root -p

常見問題

  • 找不到 my.ini:用 Everything 搜尋或查看服務啟動參數 --defaults-file
  • 5.7+ 欄位名:authentication_string,非 password
  • 首次登入報 1820:執行 SET PASSWORD = PASSWORD('newpass');

安全提醒

完成後務必移除 skip-grant-tables,否則任何本機使用者可免密登入 root。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved