忘記 MySQL root 密碼,且擁有作業系統最高權限(Linux root / Windows Administrator)。
/etc/init.d/mysql stop
# 或
ps aux | grep mysql
kill -TERM 進程ID
mysqld_safe --skip-grant-tables &
此模式下不載入授權表,任何人可無密碼登入。
mysql mysql
UPDATE user SET Password=PASSWORD('新密碼') WHERE User='root';
FLUSH PRIVILEGES;
/etc/init.d/mysql restart
mysql -uroot -p新密碼
net stop mysql 或工作管理員結束 mysqld.exe。mysqld --skip-grant-tables(於安裝目錄 bin 下執行)。--skip-grant-tables 期間資料庫完全無保護,務必在可信網路/本機操作,完成後立即重啟正常模式。Password 欄位改為 authentication_string,語法調整為:UPDATE user SET authentication_string=PASSWORD('新密碼') WHERE User='root';ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';。MySQL 5.0 / Fedora Core 3 驗證通過。