ERROR 1449 (HY000): The user specified as a definer ('root'@'%') does not exist
觸發場景:調用視圖、存儲過程、觸發器、事件等定義了 DEFINER='root'@'%' 的對象,但實際資料庫中不存在 root@'%' 用戶(僅有 root@'localhost' 或 root@'127.0.0.1')。
root@'%'。CREATE USER 'root'@'%' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
ALTER VIEW view_name DEFINER = 'root'@'localhost' ...(需重建視圖定義)。SHOW CREATE PROCEDURE ...,修改 DEFINER 後重建。mysql.proc、mysql.triggers、information_schema.views 等系統表(需 skip-grant-tables,**極高風險**,不推薦生產環境)。# 導出時加參數
mysqldump --skip-definer -u root -p db_name > dump.sql
# 或導入前用 sed 移除
sed -i "s/DEFINER=[^ ]* //g" dump.sql
DEFINER,使用 CURRENT_USER 或不指定(默認調用者)。SELECT DEFINER FROM information_schema.ROUTINES/VIEWS/TRIGGERS/EVENTS,確保目標庫存在對應用戶。root@'%' 僅用於管理工具連接,業務應用使用專用帳號。