解决阿里云恢复 mysqldump 文件时没有权限的错误

在阿里云 mysql -uxx -hxxx -p dbname < file.sql 恢复文件时由于 RDS 没有 Supper 权限所以报错:

Access denied; you need (at least one of) the SUPER privilege(s) for this operation

解决方法: 去除 GTID_PURGEDDEFINER 子句:

sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/ ' your.sql > your_revised.sql
awk '{ if (index($0,"GTID_PURGED")) { getline; while (length($0) > 0) { getline; } } else { print $0 } }' your.sql | grep -iv 'set @@' > your_revised.sql

详见: https://help.aliyun.com/knowledge_detail/41701.html