简体   繁体   中英

LOAD DATA INFILE fields terminated by

I have searched through this forum but I didn't find anything related to this particular problem I'm facing with. Namely, I have a text file which I want to transfer to MySQL db, I'm using PHP for scripting.

What I want to know is can I by any chance use multiple delimiters in the FIELDS TERMINATED BY parameter:

LOAD DATA INFILE '$file'

INTO TABLE $my_table

FIELDS TERMINATED BY ';'

LINES TERMINATED BY '\\r\\n'";

My text file looks like this:

11;111111;;1111111;;;;;;1111;;;;11111;;1111111111;111111111;;;111; .....

So, by only using ';' as the delimiter I don't get the wanted results, eg in some db fields I am getting data like ;;1111; - normally there should be only numbers.

Is there any way to make all the semicolons act as a delimiter?

Your input txt file is not in proper format.

You can find and replace ;; with ; in text editor and then try loading data again into table.

Repeat this find and replace process two times to convert all semicolons to one.

\\N between the delimiters in the data file. This marks the field as null when sql loads it.

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