如果您使用的是 RDS 的 AWS Aurora 风格,那么您很幸运:https://aws.amazon.com/about-aws/whats-new/2017/06/amazon-aurora-can-export-data-into-amazon-s3/
如果您使用带有 RDS 的普通 MySql,我有一个解决方法可以将一些数据重定向到 .csv。我将 aws data pipeline 产品与 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"
}
}
(虽然我对完成后的结果感到满意,但我不得不承认我花了一周的时间来设置这条管道!它已经每天运行 4 个月,没有任何问题,但如果我要再做一次,我会改为升级到 Aurora 并使用他们的 INTO OUTFILE S3 语法)