You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS RDS MySQL执行LOAD DATA FROM S3遇权限报错求助

问题:通过跳板机连接AWS RDS MySQL导入S3数据失败

操作场景

通过跳板机连接AWS RDS MySQL,执行以下命令导入S3中的CSV数据:

LOAD DATA FROM S3 's3://com.price.images/devops/price_final_mmvy_01162024.csv'
INTO TABLE price_2024
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' 
IGNORE 1 ROWS 
(city_id,variant_id,year,month,km,fairdealer,gooddealer,excellentdealer,fair_max_quote_price,fair_min_quote_price,good_min_quote_price,excellent_min_quote_price,excellent_max_quote_price,quote_price,quote_increased_by,state_id,min_quote_price,max_quote_price,good_max_quote_price,very_good_min_quote_price,very_good_max_quote_price,status);

首次报错

ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access

尝试修复后的报错

执行以下命令:

SET GLOBAL local_infile=1;

LOAD DATA FROM S3 's3://com.price.images/devops/price_final_mmvy_01162024.csv'
INTO TABLE price_2024
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n' 
IGNORE 1 ROWS 
(city_id,variant_id,year,month,km,fairdealer,gooddealer,excellentdealer,fair_max_quote_price,fair_min_quote_price,good_min_quote_price,excellent_min_quote_price,excellent_max_quote_price,quote_price,quote_increased_by,state_id,min_quote_price,max_quote_price,good_max_quote_price,very_good_min_quote_price,very_good_max_quote_price,status);

得到两个报错:

ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation

解决方案

1. 配置RDS与S3的权限关联

  • 给RDS实例绑定的IAM角色添加AmazonS3ReadOnlyAccess权限,确保该角色已在RDS控制台的「配置 > IAM角色」中关联到目标实例。
  • 检查RDS参数组,确认aws_s3.enable参数设置为ON。

2. 连接时开启local_infile

普通用户无SUPER权限,无法修改全局local_infile参数,需在连接MySQL时直接开启该选项:
使用mysql客户端连接时,添加--local-infile=1参数:

mysql -h <你的RDS端点> -u <用户名> -p --local-infile=1

如果通过跳板机连接,确保跳板机上的mysql客户端调用时包含此参数。

3. 授予用户S3导入权限

用管理员账号执行以下SQL,给目标用户授予LOAD FROM S3权限:

GRANT LOAD FROM S3 ON *.* TO '<你的用户名>'@'%';

4. 备选方案:使用AWS批量导入工具

如果上述方法仍有问题,可改用AWS Data Pipeline或AWS Glue完成数据导入,这类服务无需操作MySQL权限,适合批量数据场景。

额外检查

  • 确认跳板机的安全组和NACL允许访问RDS实例和S3存储桶的流量。
  • 检查S3存储桶的访问策略,允许RDS关联的IAM角色读取该桶内容。

内容的提问来源于stack exchange,提问作者Raghunath Kushawaha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 09:33:19