2

I was trying to import a CSV file into a table with an auto-incrementing column named "id". I do not want to insert the id column as it numbers itself, but after many tries I cannot get this to work. Here is the query I tried:

LOAD DATA LOCAL INFILE 'C:\\CaliberMap.csv'
INTO TABLE sefeed_calibermap 
(SiteCaliber,SE1Caliber,SE2Caliber,Other1Caliber,Other2Caliber,Other3Caliber,Other4Caliber)
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;

When I execute the query, I get the following message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMI' at line 4

I'm stumped! I wrote this query after reading examples from many different places on the Internet, so the syntax looks correct.

I'm running PhpMyAdmin version 5.6.10.

2
  • Do you have an ID column in your CSV file? Commented Mar 24, 2013 at 2:39
  • If you give us a couple of sample lines from the CSV file, and perhaps also the MySQL table description, we might be better able to help. As an alternative, try using HeidiSQL instead of PhpMyAdmin: it has a wizard to import CSV files, which can help. (HeidiSQL is a desktop program for managing MySQL databases, and I find it a lot easier to use than PhpMyAdmin.) Commented Mar 27, 2013 at 16:59

1 Answer 1

7

You are confused I think by the documentation you have read. Try this:

LOAD DATA LOCAL INFILE 'C:\\CaliberMap.csv'
INTO TABLE sefeed_calibermap     
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(SiteCaliber,SE1Caliber,SE2Caliber,Other1Caliber,Other2Caliber,Other3Caliber,Other4Caliber);

The table fields should be at the end.

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

2 Comments

This is correct per the load-data specs: dev.mysql.com/doc/refman/5.1/en/load-data.html
thanks folks! I'm new to MySQL (thanks to the new MS pricing MSSQL by the cpu core, sending the price into the stratosphere, I'm forced to move to MySQL)

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.