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? Tha开发者_高级运维nks
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.
head -c 1000 myFile.txt | tail -n 950
would give the 50-1000 lines. I'd recommend separating the pre-processing stage from dataload
精彩评论