MySQL: Load Data Infile from CSV that consist of comma in VARCHAR field via /r/learnprogramming


MySQL: Load Data Infile from CSV that consist of comma in VARCHAR field

Below is the code that I use to import CSV file to MySQL database. It works well to divide all the field and its record.

LOAD DATA INFILE 'file.csv' INTO TABLE customer FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' ( ID, name, salary, address, status ); 

However, when there is a VARCHAR or TEXT field which consist of comma (','), it works improperly. It is because I use FIELDS TERMINATED BY ',' that used to separate each field record.

So, for example, if a customer with salary 50,000 (double), it split the field normally. But, if the customer address is Java Road 15, Hong Kong (varchar/text), Java Road 15 will be saved in address field, while the Hong Kong will be saved to status field. This basically remove any record inside the status field. Any clue for this problem? Thanks in advance.

Submitted July 17, 2017 at 11:14PM by epstanza
via reddit http://ift.tt/2u3m9C8

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s