If you would prefer to be given warnings rather than have the import fail, you should
set the SQL mode to ANSI. In a front end, or at the SQL prompt when using the
SQL command line program, enter the following:
SET sql_mode = ‘ANSI’
The complete syntax for the LOAD DATA INFILE command is available in the
MySQL documentation, but a typical statement will have these clauses:
LOAD DATA INFILE ‘complete path to text file’
INTO TABLE TableName
FIELDS TERMINATED BY ‘,’
OPTIONALLY ENCLOSED BY ‘”’
LINES TERMINATED BY ‘\n’
IGNORE n LINES
The character you enter in the FIELDS TERMINATED BY line is the delimiter (in
the above column a comma) and the character(s) entered in the LINES
TERMINATED BY line will depend on the operating system that created the
delimited text file. Files created on Macs may have only the ‘\n’ or ‘\r\ characters,
while those created by Windows machines may end with the combination ‘\r\n’
Looking at the text file in an editor that shows hidden characters can help you
determine in the line-ending character. If you use the wrong one, the worst that will
happen is that MySQL will try to load the entire file into one row. Try one of the
other combinations if that happens.
Here is what the command would look like for the Donations data.
LOAD DATA INFILE ‘c:/mydata/Donations.csv’
INTO TABLE Donations
FIELDS TERMINATED BY ‘,’
OPTIONALLY ENCLOSED BY ‘”’
LINES TERMINATED BY ‘\r\n’
IGNORE 1 LINES
If there are problems with the import, these will be reported as warnings, if you
turned off strict mode, or the first error will be reported as an error, if strict mode is
on (and the import will stop). Troubleshooting issues with LOAD DATA INFILE is
one of the reasons why many users prefer to use the import utility available in front
ends such as Navicat or Sequel Pro.