1

I am trying to load csv file into my table. I've run the following code which throws error

LOAD DATA LOCAL INFILE 'info.csv' INTO TABLE tbl_countryip (ipstart, ipend, countrycode) FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n'  ;

The error is

bash: syntax error near unexpected token `('

I even tried after removing the space between tablename and column names but still the same error Thanks in advance

2
  • i dont understand (ipstart, ipend, countrycode) Commented Dec 29, 2015 at 5:50
  • these are all column names Commented Dec 29, 2015 at 5:52

2 Answers 2

1

Try this syntax-

LOAD DATA LOCAL INFILE 'info.csv'
INTO TABLE tbl_countryip
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(col1, col2, col3, col4, col5...);

Hope the below reference link help you

MYSQL-LOAD DATA INFILE

Sign up to request clarification or add additional context in comments.

1 Comment

Actually I read that already they mentioned The column list can contain either column names or user variables. That's why I have given the column names
0

You need to do following changes:

  1. Remove column names. Ensure columns and their sequence in csv file matches exactly with that of table.
  2. Remove \r from LINES TERMINATED BY

Updated Query

LOAD DATA LOCAL INFILE 'info.csv'
INTO TABLE tbl_countryip
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

If first row in your csv file is a column name, use IGNORE 1 LINES after LINES TERMINATED.

1 Comment

the problem is the columns doesn't match

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.