简体   繁体   English

导出 mysql 查询到 amazon s3 bucket

[英]Export mysql query to amazon s3 bucket

Based on the accepted answer here , I am able to export the results of mysql query to a csv file on my Amazon EC2 instance using the following:根据此处接受的答案,我可以使用以下命令将 mysql 查询的结果导出到我的 Amazon EC2 实例上的csv文件:

mysql -user -pass -e "SELECT * FROM table" > /data.csv

However, as the file exported is large, I want to export an Amazon s3-bucket ( s3:\\mybucket ) which is accessible from my EC2 instance但是,由于导出的文件很大,我想导出一个可从我的 EC2 实例访问的 Amazon s3-bucket ( s3:\\mybucket )

I tried:我试过了:

mysql -user -pass -e "SELECT * FROM table" > s3:\\mybucket\data.csv

But it doesn't export the file.但它不会导出文件。

If you want to use the mysql command line program, then you have two choices: 如果要使用mysql命令行程序,则有两种选择:

  • Increase the size of your instance's storage so that the file can be created. 增加实例存储的大小,以便可以创建文件。 Then copy the file to S3 然后将文件复制到S3
  • Create a separate program or script that reads from Standard Input and writes to S3. 创建一个单独的程序或脚本,该程序或脚本从标准输入读取并写入S3。

Another solution would be to create a simple program that processes your SELECT and directly writes to S3. 另一个解决方案是创建一个简单的程序来处理SELECT并直接写入S3。 There are lots of examples of this on the Internet in Python, Java, etc. 互联网上有很多使用Python,Java等的示例。

In addition to the accepted answer, if you are using the Aurora, then you can do除了接受的答案外,如果您使用的是 Aurora,那么您还可以

SELECT * FROM table INTO OUTFILE S3 's3:\\mybucket\table-data';

https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.SaveIntoS3.html https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.SaveIntoS3.html

Alternate approach,替代方法,

mysqldump -h [db_hostname] -u [db_user] -p[db_passwd] [databasename] [tablename] | aws s3 cp - s3://[s3_bucketname]/[mysqldump_filename]

it'll directly store the file to s3 without occupying space它会直接将文件存储到s3而不占用空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM