I have several CSV files that I want to upload to my database, but the CSV file contains many more columns than in my database. How to import only selected columns from a CSV file into my database?
For arguments, let's say CSV contains a header row with column headings from A to Z, and then two million rows with values ββfor columns from A to Z. Say my table myTest contains B, N and S, so I only want to import columns B , N and S from a CSV file in myTest.
I planned to do:
mysqlimport --local --columns=B,N,S --ignore-lines=1 --delete --default-character-set=latin1 --fields-optionally-enclosed-by=\" --fields-terminated-by=\, --lines-terminated-by=\r\n myDb myTest.csv
But this fills rows B, N, and S with the values ββof columns A, B, and C, and not with the values ββof columns B, N, and S as I wanted.
Any suggestions how can I import only B, N and S?
import mysql csv
niklassaers
source share