David
David

Reputation: 14414

How to import partial contents of a file into a MySQL database?

What is the correct syntax to import a part of a file into a MySQL database? For instance, I want to only load lines 50 to line 1000.

Currently my SQL statement imports an entire file into the database.

LOAD DATA INFILE 'myFile.txt' INTO TABLE myTable (col1, col2) FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'

I want to be more selective. Any suggestions? Thanks

Upvotes: 1

Views: 3469

Answers (2)

kuriouscoder
kuriouscoder

Reputation: 5582

head -c 1000 myFile.txt | tail -n 950 would give the 50-1000 lines. I'd recommend separating the pre-processing stage from dataload

Upvotes: 0

Oswald
Oswald

Reputation: 31685

LOAD DATA INFILE only alows you to skip lines at the beginning of the file (by saying e.g. IGNORE 49 LINES), but it will import all lines until the end of the file. See LOAD DATA INFILE Syntax for details.

Upvotes: 3

Related Questions