简体   繁体   中英

Exporting a very large MySQL table to a .CSV using a SELECT statement?

I've got a MySQL table with ~1B rows. I need to export a single column from every row into a CSV.

  1. I've tried the following but the query uses all the memory on the local machine where I'm exporting the query and the mysql process gets killed.

    mysql -uuser -ppass -h host.com --database=dbname -e "select column_name FROM table_name" > column_name_export.csv

  2. I can't use a SELECT INTO OUTFILE because the MySQL instance is running in Amazon RDS and I don't have access to the server.

Is there a MySQL utility to export this in batches, or do I need to write a script to select over ranges of ids?

One way to do it is using Server-side cursors .

But in my case even the server ran out of memory (for very large tables), so I opted for splitting the file into multiple batches, ordered by any id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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