SUPER 權限的賬號可登錄修改。systemctl stop mysqld
# 或
service mysqld stop
# 或強制
killall -TERM mysqld
/usr/bin/mysqld_safe --skip-grant-tables --skip-networking &
--skip-grant-tables:不載入權限表,任意用戶無密碼可登錄,**極度危險**,**必須配合 --skip-networking 禁用網絡監聽**,防止外部入侵。which mysqld_safe)。mysql -u root
-- 進入 mysql> 提示符
USE mysql;
UPDATE user SET authentication_string = PASSWORD('新密碼') WHERE User = 'root';
-- MySQL 5.7+ 字段為 authentication_string,5.6 為 password
FLUSH PRIVILEGES;
EXIT;
# 關閉 --skip-grant-tables 進程
killall mysqld
# 正常啟動
systemctl start mysqld
mysql -h localhost -u root -p
# 輸入新密碼登錄成功
PASSWORD() 函數已移除,直接設置哈希值或使用 ALTER USER(但需授權表載入)。UPDATE user SET authentication_string = '' WHERE User='root'; FLUSH PRIVILEGES; 置空密碼,正常啟動後再 ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpwd';。--skip-grant-tables 期間任何本地用戶均可無密碼登錄為 root。生產環境操作前請:
--skip-networking 生效。