从 RDS SELECT * INTO OUTFILE 到 S3

8ad*_*ger 2 mysql amazon-s3 rds

我正在尝试将一些数据重定向到.csv一个RDS实例。我尝试重定向到EC2 box我们用作客户端的一个,并收到权限错误。我有点明白这一点。首先,是否有解决方法?或者我可以

SELECT * INTO OUTFILE S3:.... from table bob....
Run Code Online (Sandbox Code Playgroud)

这是一个每周使用动态参数(例如日期和数据库名称)运行的过程。我目前使用 MYSQL 存储过程执行动态 SQL。

提前致谢。

Tom*_*Tom 7

如果您使用的是 AWS Aurora 风格的 RDS,那么您很幸运:https : //aws.amazon.com/about-aws/whats-new/2017/06/amazon-aurora-can-export-data-into -亚马逊-s3/


如果您在 RDS 中使用普通的 MySql,我有一个解决方法可以将一些数据重定向到.csv. 我使用了 aws数据管道产品CopyActivity- 它可以将数据从您指定的 SQL 查询复制到您指定的 S3 存储桶。

这是我的管道定义的摘录yml,显示了输入、输出和CopyActivity

{
  "myDescription": "Mysql datanode that represents the input database and query that gets the marketing table data.",

  "type": "MySqlDataNode",
  "name": "SourceRDSTable",
  "id": "SourceRDSTable",
  "connectionString": "jdbc:mysql://marketing.example.com:3306/schemaname",
  "table": "marketing",
  "selectQuery": "SELECT * FROM schemaname.marketing WHERE active=1 AND isOptedOut=0",
  "username": "mysqluser",
  "*password": "redacted"
},
{
  "myDescription": "S3 datanode that represents the S3 directory where the table data will be stored.",

  "type": "S3DataNode",
  "name": "S3OutputLocation",
  "id": "S3OutputLocation",
  "filePath": "s3://mys3bucket/output/marketing_dump_#{format(@scheduledStartTime, 'YYYY-MM-dd')}.csv"
},
{
  "myDescription": "CopyActivity used to dump a subset of the marketing table to S3 as csv",

  "type": "CopyActivity",
  "name": "Copy marketing table to S3",
  "id": "RDStoS3CopyActivity",
  "input": {
    "ref": "SourceRDSTable"
  },
  "output": {
    "ref": "S3OutputLocation"
  },
  "runsOn": {
    "ref": "ec2_worker_instance"
  }
}
Run Code Online (Sandbox Code Playgroud)

(虽然我对现在完成的结果很满意,但我不得不承认我花了一个星期来设置这条管道!它已经每天运行了 4 个月没有出现任何故障,但如果我再做一次,我会而是升级到 Aurora 并使用它们的INTO OUTFILE S3语法)