Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle csv with commas in string fields using mysqlimport

I have the following import:

mysqlimport --columns=column1,column2,etc --ignore-lines=1 --fields-terminated-by=, --verbose --local -u myuser -p mytable myfile.csv

I have a csv with the following:

Beatguide,company,/organization/beatguide,beatguide.me,http://beatguide.me,DEU,,Berlin,Berlin,,"",operating,"Beatguide, an electronic music events listing and discovery platform adding sound to the experience of searching for shows and club nights.",electronics|events|music,consumer electronics|events|hardware|media and entertainment|music and audio,0,,2013-01-01,,,,11-50,,,http://www.facebook.com/beatguide.me,,

You can see the short description has a comma, but is enclosed in quotes:

"Beatguide,

an electronic music events listing and discovery platform adding sound to the experience of searching for shows and club nights."

Currently, the above mysqlimport statement splits this field. What parameter do I add to the mysqlimport statement to have it respect the quotes and insert the string with the comma instead of splitting it?

like image 544
Atma Avatar asked Dec 03 '25 08:12

Atma


1 Answers

I added the following option:

--fields-optionally-enclosed-by='"'

This solved my problem.

like image 106
Atma Avatar answered Dec 05 '25 23:12

Atma