How to export SQL Output directly to CSV on Amazon RDS

旧巷老猫 提交于 2020-01-24 17:15:10

问题


Amazon doesn't give Access to RDS Server directly ( they expose it only through service RDS) hence, "select into outfile" doesn't work.. Even the master user does not have privileges of FILE.

I created ticket with Amazon; talked at length with them.. They suggested few work-around like using Data Pipeline etc.. but all are too complicated..

Surely one of the way could be to use tool like MYSql Workbench --> execute query --> Export to CSV.. Only problem with this approach is that you need to execute same query twice on server and is problematic if your output is having thousands of rows.


回答1:


Just write the query in a file a.sql. The SQL Should be in this format:

select concat( '"',Product_id,'","',    Subcategory,'","',  ifnull(Product_type,''),'","',     ifnull(End_Date,''), '"') as data from tablename

mysql -h xyz.abc7zdltfa3r.ap-southeast-1.rds.amazonaws.com -u query -pxyz < a.sql > deepak.csv

Output will be there in file deepak.csv



来源:https://stackoverflow.com/questions/33007523/how-to-export-sql-output-directly-to-csv-on-amazon-rds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!