在 CentOS 環境下遺忘 MySQL root 密碼,可透過 --skip-grant-tables 跳過權限驗證進行重置。本文提供經測試可行的完整指令序列。
/etc/init.d/mysql stopcd /usr/local/mysql/bin
./mysqld_safe --skip-grant-tables &mysqld --skip-grant-tables &./mysql -uroot -p (直接按 Enter)UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root';
FLUSH PRIVILEGES;
QUIT;/etc/init.d/mysql restart重置完成後請立即以新密碼驗證登入。