Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm building an app to import data from a text file to a database.

I want to import only specific lines from the text file. With Navicat I found that we could limit number of line when importing data.

I also found an article saying that we could limit it, so I tried this:

load data infile 'c:/coop/wkwk.txt' into table jo fields 
    terminated by '|' lines terminated by '\n' limit 10,100;

But I get an error in SQL syntax, what is the QUERY to make this work?

share|improve this question
add comment

2 Answers

You can't use LIMIT on LOAD DATA INFILE. The only thing you can do, with regard to your question, is to skip a certain number of rows:

LOAD DATA INFILE ... INTO TABLE ... IGNORE 17 LINES

But you then have no way stopping until the end of file. See documentation.

share|improve this answer
add comment

If you are using Unix/Linux you could try using a fifo buffer:

mkfifo /tmp/mysql.pipe 
# Select rows 101 to 110
sed -n 101,110p filename > /tmp/mysql.pipe & 
mysql –uusername -p -Ddatabasename -e "LOAD DATA LOCAL INFILE ' /tmp/mysql.pipe ' INTO TABLE tablename"

rm -f /tmp/mysql.pipe
share|improve this answer
    
This is a very bold answer. +1 because I like bold !!! –  RolandoMySQLDBA Sep 10 '12 at 17:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.