简体   繁体   中英

How do I deal with semicolon in a cell when the file I am uploading semicolon delimited?

I am using load data infile to upload a 2gig csv file into mysql and getting some warnings that indicate that some of the cells include a semicolon when the actual csv file I am uploading is semicolon separated.

I suppose that changing the delimiter from semicolon may be an option but I do not have control over the export I am working with. Not sure how to do this without a find replace which obviously wouldnt work as it would just replace the semicolon that needs to remain in the field it has been exported to.

Here is what I am using:

load data infile '/file/path/bigfile.csv'  
into table table_name fields terminated by ';'  
LINES TERMINATED BY '\r\n' ignore 1 lines 
(Column1, Column2, Column3, ....);

I guess the ultimate question is can you use a regex as a delimter when using load data infile...having problems finding this answer.

You have to mention the fields separated by in LOAD DATA command as:

LOAD DATA LOCAL INFILE 'abc.csv' INTO TABLE abc
FIELDS TERMINATED BY **';'** 
ENCLOSED BY '"' 
LINES TERMINATED BY '\r\n'

FIELDS TERMINATED BY ' ; ' is the main part to edit in your case.

Also you might be change the delimiter from semicolon to something else..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM