I’m trying to load a CSV into MySQL using the LOAD DATA INFILE technique. It’s working fine, but I have a problem where some columns use double quotes and some do not.
Example:
something,123,something,"Bauer, Jack",123,something
What happens is the commas inside the quotes break the import, so my data is all jacked up at the end. Not sure how to get the import to escape commas inside the double quotes.
mysql --user=<USER> --password=<PASS> -e "LOAD DATA INFILE '<FILENAME>' INTO TABLE <TABLENAME> FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' (col1, col2, col3, ...)" <DATABASE>
You need to execute the statement LOAD DATA INFILE with the additional option
Thus the whole statement becoming
For further readings, please consult the excellent MySQL Reference Manual e.g. for MySQL 5.1 GA.