通用、無需舊密碼的 root 密碼重置標準流程(適用 MySQL 5.6/5.7/8.0、MariaDB、Percona)。
systemctl stop mysqld 或 /etc/init.d/mysql stop。mysqld_safe --skip-grant-tables --skip-networking &--skip-networking 禁止遠程連入,安全第一。mysql -u root mysqlUPDATE user SET authentication_string=PASSWORD('newpwd') WHERE User='root';authentication_string,5.7 用 Password;ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpwd';FLUSH PRIVILEGES;systemctl restart mysqldmysql -uroot -pnewpwd。--skip-networking 導致裸奔 3306 端口。PASSWORD() 已移除,必須用 ALTER USER 或直接更新 authentication_string(需 FLUSH PRIVILEGES)。mysqld_safe 寫入 socket/pid,查看 /var/log/mysqld.log 或 ausearch -m avc。--defaults-file=/etc/my.cnf.xxx。若僅忘記應用賬號密碼,root 正常,可用 mysql_config_editor print --login-path=app 查看明文(需 root 權限)。