Search code examples
mysqlcsvfill

Fill MySQL table with the data from CSV file


There is a CSV file with the following data:

1;8-25-2010;0:05;210;4
2;8-25-2010;2:45;412;5
3;8-25-2010;3:40;300;3
4;8-25-2010;4:45;226;6
5;8-25-2010;5:20;206;4
6;8-25-2010;5:25;216;3

And there is MySQL Table:

CREATE TABLE IF NOT EXISTS `Schedule` (
  `ID` SMALLINT NOT NULL AUTO_INCREMENT,
  `Num` INT(10),
  `PlannedDate` DATE,
  `PlannedTime` TIME NOT NULL,
  `resQty` INT(3) NOT NULL,
  `stID` VARCHAR(10) NOT NULL,
  PRIMARY KEY (`ID`),
  FOREIGN KEY `stID` (`stID`) REFERENCES Stands (`stID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Now I need to fill this table with the data from CSV file. For this I'm using the following code:

TRUNCATE TABLE testDB.Schedule;
LOAD DATA LOCAL INFILE 'C:\\temp\\Input.csv'
INTO TABLE testDB.Schedule FIELDS TERMINATED BY ';' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n' (Num,PlannedDate,PlannedTime,stID,resQty);

But the error message says that "Data truncated for column PlannedDate at row1", ErrorNr. 1265. The same error message for all rows.


Solution

  • The date has the wrong format, it should be 2012-01-19