Question

I am running this MySQL command:

LOAD DATA LOCAL INFILE 'books.csv'
INTO TABLE BOOK (Book_id, @dummy, Title, Publisher_name, @dummy, @dummy)
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;

I am getting an error:

ERROR 1064 (42000): 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 '\t' LINES TERMINATED BY '\r\n' IGNORE 1 LINES' at line 3

What am I doing wrong here?

Was it helpful?

Solution

http://dev.mysql.com/doc/refman/5.6/en/load-data.html shows the syntax. The clause naming columns goes after the IGNORE clause.

LOAD DATA LOCAL INFILE 'books.csv'
  INTO TABLE BOOK 
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(Book_id, @dummy, Title, Publisher_name, @dummy, @dummy);

OTHER TIPS

You have an error in your SQL syntax; 

Take a deep breath, this error is infurating and why MySQL sucks. You have a lot of work work to do to figure out what you did wrong:

If you get this error it means the SQL parser encountered an error because of one of the following reasons:

  1. A misplaced, missing, or unnecessary symbol like !@#$%^&*()-_=+[]{}\|;:'",.<>/?.
  2. A misplaced, missing or unnecessary keyword like select, into, or any of the thousands of others.
  3. You have unicode characters in your query.
  4. Too little or too much whitespace between keywords.
  5. Unmatched single quotes, double quotes, parenthesis or braces.

Break the SQL down into smaller and smaller pieces until you are left with the minimum possible statement that fails.

The syntax error will leap out at you, you will slap your forehead, and be one step closer to uninstalling the MySQL badware and getting postgreSQL instead which does not subject the user to such infuriating general errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top