简体   繁体   中英

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

LOAD DATA INFILE only alows you to skip lines at the beginning of the file (by saying eg 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 head -c 1000 myFile.txt | tail -n 950 would give the 50-1000 lines. I'd recommend separating the pre-processing stage from dataload

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