忘記 Root 密碼、無其他管理帳號可登入。
net stop mysql / Linux: systemctl stop mysqldmysqld_safe --skip-grant-tables &mysqld --skip-grant-tables(需另開視窗)mysql -u rootmysql> 提示符,無需密碼。UPDATE mysql.user SET Password=PASSWORD('NewStrongPassword') WHERE User='root';FLUSH PRIVILEGES;QUIT;--skip-grant-tables 進程,正常啟動:net start mysql / Linux: systemctl start mysqldmysql -u root -p'NewStrongPassword'--skip-grant-tables 使 mysqld **不載入授權表**,所有連線直接擁有超級權限,繞過密碼驗證。修改完 mysql.user 表後,FLUSH PRIVILEGES 重新載入授權緩存,新密碼即時生效。
bind-address=127.0.0.1 限制本機訪問,或防火牆臨時封鎖 3306 埠。-- 5.7
UPDATE mysql.user SET authentication_string=PASSWORD('newpass') WHERE User='root';
-- 8.0 (caching_sha2_password)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpass';
若 UPDATE 方式無效,嘗試版本對應語句。