I have a file, say data.csv, which is coming into my server, and which I want to import to the data table in a MySQL database using mysqlimport.
My issue is, this file has a lot more data than I actually want to import. It is used by another server before me which needs all this data, but I only need a handful of columns from it.
Is there a way to specify what columns I want mysqlimport to use?
I thought it would look something like
mysqlimport --columns="field_1","field_2","field_42","field_31","field_16","field_4" db data.csv
but the table just contains the first 6 fields of the file instead. If needs be, I can rearrange the table so that the fields I want are in order (i.e., I'd be running --columns="field_1","field_2","field_4","field_16",...).
I'm vaguely aware that this could be done using sed, but I'm curious whether mysqlimport natively supports it?
EDIT: The accepted answer isn't exactly what I was hoping for, but I think the answer is, "no, it sadly doesn't support it". In any case, check out the accepted answer and comments for workarounds!