首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

Windows MySQL 1045 錯誤:Access denied for user 'root' 解決方案匯總

     編輯:MySQL 資料庫相關知識

錯誤現象

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

方案一:官方 init-file 重置法 (Windows 原生)

  1. 管理員身份登入,停止 MySQL 服務 (services.msc 或任務管理器殺進程)
  2. 建立文本文件 C:\mysql-init.txt,內容單行:
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
  3. CMD 執行:
    C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt
  4. 服務啟動後刪除 mysql-init.txt,正常重啟服務

方案二:Linux/通用 --skip-grant-tables 法

# 1. 停庫
/etc/init.d/mysql stop
# 2. 跳過權限啟動
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# 3. 免密登入修改
mysql -u root mysql
UPDATE user SET Password=PASSWORD('newpassword') WHERE USER='root';
FLUSH PRIVILEGES;
QUIT
# 4. 正常重啟
/etc/init.d/mysql restart

方案三:Debian/Ubuntu 專用 debian-sys-maint 帳號

# 讀取 /etc/mysql/debian.cnf 內 [client] 節點的 user/password
mysql -u debian-sys-maint -p
UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE USER='root';
FLUSH PRIVILEGES;

方案四:Windows CMD 簡易版

# 1. 管理員 CMD 停止服務或殺 mysqld-nt
# 2. 啟動跳過權限
d:\mysql\bin\mysqld-nt --skip-grant-tables
# 3. 新開 CMD 重置密碼
d:\mysql\bin\mysqladmin -u root flush-privileges password "newpassword"
# 4. 重啟服務

事後驗證

mysql -u root -p
# 輸入新密碼登入成功即可
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved