简体   繁体   中英

MySQL ERROR 1064 cause (LOAD DATA INFILE)

When I run this SQL commands within MySQL

LOAD DATA INFILE 'myFile.csv' INTO myTable FIELDS TERMINATED BY ','

I get this error:

ERROR 1064 (42000) at line 1: 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 'TO myTable FIELDS TERMINATED BY ','' at line 1

This message isn't very helpful, it can appear for one of countless syntax errors.

How do I find out what mistake I've made with such a generalized "it won't work" error message?

try

LOAD DATA INFILE 'myFile.csv' INTO TABLE myTable 
FIELDS TERMINATED BY ','

(chage TO to INTO TABLE)

Taken from the documentation

This MySQL error:

You have an error in your SQL syntax; check the manual.

Is the most infuriating answer MySQL could give. There are about a billion mistakes you could have made which produces this error. It's part of the reason MySQL sucks and you should feel bad for continuing to use it. PostgreSQL would never give such a lame error message.

You're going to have to divide and conquer your problem.

Ideas:

  1. Take a second look at usage of these characters: {}[]|\\'";:,<.>/?!@#$%^&*()_+ in your SQL statement to make sure you put them in the right place. If they are out of place or lacking proper whitespace padding it could causes this error.

  2. Make sure all of your double quotes and single quotes have matching partners. Sometimes the SQL parser gets confused if you don't escape something right.

  3. Retype your entire answer to make sure there is not unicode characters in your query.

  4. Make sure the whitespace delimiting your words are spaces and normal newlines, not ascii whitespace, extraneous line feeds or spacing characters.

  5. Make sure you are using the correct keywords in the correct order. And that you have not omitted a keyword. "INTO TABLE blah" is not the same as "Into blah", and infinite variants on this theme.

  6. Make sure you have semicolons where they belong. Remove the ones that don't belong.

Delete MySQL, and if anyone asks why, then say: "Because the developers forgot to link specific errors to meaningful unique error messages".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM