Home >Database >Mysql Tutorial >How do I export data from Amazon RDS MySQL to CSV?
Exporting Data from Amazon RDS MySQL to CSV
Exporting an entire table to CSV format from an Amazon RDS MySQL instance can pose a challenge due to the lack of a dedicated file server. To address this, consider the following solutions:
Using the MySQL Command Line Client
Connect to your RDS MySQL instance using the mysql command:
mysql -u username -p --database=dbname --host=rdshostname --port=rdsport --batch
Select the data from the desired table and pipe the output to reformat it as CSV:
-e "select * from yourtable" \ | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > yourlocalfilename
Using a Predefined Field List
If you know the fields upfront, you can use a simpler approach:
mysql -uroot -ppassword --database=dbtest \ -e "select concat(field1,',',field2,',',field3) FROM tabletest" > tabletest.csv
This method allows you to customize the field order and excludes unsupported characters like line breaks and tabs. By following these steps, you can successfully export a table from Amazon RDS MySQL to a CSV file.
The above is the detailed content of How do I export data from Amazon RDS MySQL to CSV?. For more information, please follow other related articles on the PHP Chinese website!