The user specified as a definer ('root'@'%') does not exist——从MySQL Dumps中删除DEFINER子句

sed -i -e 's/DEFINER=`root`@`%`//g' dump.sql
导入脚本数据后,使用当中出现如下错误:
The user specified as a definer ('root'@'%') does not exist
此种报错主要是访问存储过程、函数或视图文件没有权限引起的。

grant all privileges on *.* to root@"%";

该问题原因是导入的脚本中含有DEFINER子句,而当前用户无权限访问:

MySQL转储的备份脚本中经常含有DEFINER子句

查看脚本dump.sql ,可以看到存在DEFINER子句,这在导入过程中
[root@db1 bak]# cat dump.sql |grep DEFINER

CREATE DEFINER=`root`@`%` FUNCTION
CREATE DEFINER=`root`@`%` PROCEDURE
CREATE DEFINER=`test`@`%` PROCEDURE

删除脚本中的(DEFINER=`root`@`%`)内容:

sed -i -e 's/DEFINER=`root`@`%`//g' dump.sql
sed -i -e 's/DEFINER=`test`@`%`//g' dump.sql

按照需要,如果需要,可删除脚本中DEFINER子句后重新执行

原文地址:https://www.cnblogs.com/connected/p/14173876.html