问题
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:
- A misplaced, missing, or unnecessary symbol like
!@#$%^&*()-_=+[]{}\|;:'",.<>/?
. - A misplaced, missing or unnecessary keyword like
select
,into
, or any of the thousands of others. - You have unicode characters in your query.
- Too little or too much whitespace between keywords.
- 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