user1847961
user1847961

Reputation: 117

Load Data Local Infile SQL

I have an extract of data that is separated by using this character |

I need to load this data into a MySQL database table but I'm struggling with the lines terminated by function.

Can anyone please help me identify the correct method to terminate these fields? My example data is below.

I've already tried '"|"' but this doesn't work for the first and last fields.

Example:

00000000|OLD TRUCK|9|13|02|Z |Z  |9999|111|99|ZZ|ZZ|ZZ|ZZ||ZZ|ZZ|99|999|2

Upvotes: 3

Views: 23700

Answers (2)

Ranjit Kumar
Ranjit Kumar

Reputation: 781

This worked for me

LOAD DATA LOCAL INFILE 'd:/test.csv' INTO TABLE test

FIELDS TERMINATED BY '|'

LINES TERMINATED BY '\n';

Upvotes: 4

Alec.
Alec.

Reputation: 5535

Try something like this:

 LOAD DATA LOCAL INFILE 'example.txt' INTO TABLE example_table
 FIELDS TERMINATED BY '|'
 LINES TERMINATED BY ',';

Upvotes: 5

Related Questions