Sugumar Venkatesan
Sugumar Venkatesan

Reputation: 4028

Error loading csv file

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

Upvotes: 1

Views: 459

Answers (2)

Sanjuktha
Sanjuktha

Reputation: 1085

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

Upvotes: 1

Samir Selia
Samir Selia

Reputation: 7065

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.

Upvotes: 0

Related Questions