以 --skip-grant-tables 跳過權限表,免密以 root 登入,更新 mysql.user 認證欄位,FLUSH PRIVILEGES 生效,移除參數正常重啟。
net stop mysqlbin 目錄:mysqld --skip-grant-tables --console(保持視窗)mysql -u rootUSE mysql;
UPDATE user SET authentication_string = PASSWORD('NewPass123!') WHERE User='root';
FLUSH PRIVILEGES;
net start mysqlmysql -u root -p'NewPass123!'vim /etc/my.cnf → [mysqld] 下加 skip-grant-tablessystemctl restart mysqldmysql -u root → 更新密碼(同 Windows 步驟 4)systemctl restart mysqlde 編輯內核行,末尾加 init=/bin/bash,按 b 啟動。mount -o remount,rw //etc/my.cnf 加 skip-grant-tables 或直接啟動 MySQL:mysqld_safe --skip-grant-tables &Ctrl+Z + bg)執行 mysql -u root 更新密碼。sync、mount -o remount,ro /、rebootALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewPass123!';
FLUSH PRIVILEGES;
8.0 預設 caching_sha2_password,舊客戜端需指定 mysql_native_password。
mysql_secure_installationUPDATE user SET Host='localhost' WHERE User='root'; FLUSH PRIVILEGES;