导出表从Amazon RDS成csv文件 [英] Exporting table from Amazon RDS into a csv file
问题描述
我在亚马逊RDS运行MySQL数据库,我想知道如何将整个表导出为CSV格式。我目前使用MySQL服务器在Windows上查询亚马逊的数据库,但是当我试图运行一个出口,我得到一个错误,可能是因为没有专门的文件服务器,亚马逊RDS。有没有什么解决办法?
I have a mysql database running in Amazon RDS, and I want to know how to export an entire table to csv format. I currently use mysql server on Windows to query the Amazon database, but when I try to run an export I get an error, probably because there's no dedicated file server for amazon RDS. Is there any solution to this?
推荐答案
presumably你正试图从一个亚马逊RDS <出口/ A>通过 SELECT ... INTO OUTFILE
查询,这将产生这个确实是经常遇到的问题数据库,如见导出数据库到CSV 。各 AWS团队响应确认您缺少服务器访问preventing出口的假设:像这样,并通过出口的以CSV格式的数据通过选择数据在mysql命令行客户端,并通过管道将输出格式化数据作为CSV 的,像这样提出另一种方法,以及P>
Presumably you are trying to export from an Amazon RDS database via a SELECT ... INTO OUTFILE
query, which yields this indeed commonly encountered issue, see e.g. export database to CSV. The respective AWS team response confirms your assumption of lacking server access preventing an export like so, and suggests an alternative approach as well via exporting your data in CSV format by selecting the data in the mysql command line client and piping the output to reformat the data as CSV, like so:
mysql -u username -p --database=dbname --host=rdshostname --port=rdsport --batch
-e "select * from yourtable"
| sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > yourlocalfilename
用户fpalero 提供了一种替代并理应更简单的方法,如果你知道,并指定该领域的前期:
User fpalero provides an alternative and supposedly simpler approach, if you know and specify the fields upfront:
mysql -uroot -ppassword --database=dbtest
-e "select concat(field1,',',field2,',',field3) FROM tabletest" > tabletest.csv
祝你好运!
这篇关于导出表从Amazon RDS成csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!