LOAD DATA INFILE error 1064

烈酒焚心 提交于 2020-02-03 09:46:49

问题


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?


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/19819206/load-data-infile-error-1064

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!