Error Code: 1406. Data too long for column - MySQL

前端 未结 8 1615
抹茶落季
抹茶落季 2020-11-27 05:26

Error Code: 1406. Data too long for column

CREATE  TABLE `TEST` 
(

  `idTEST` INT NOT NULL ,

  `TESTcol` VARCHAR(45) NULL ,

  PRIMARY KEY (`idTEST`) 
);
         


        
8条回答
  •  野性不改
    2020-11-27 05:56

    Besides the answer given above, I just want to add that this error can also occur while importing data with incorrect lines terminated character.

    For example I save the dump file in csv format in windows. then while importing

    LOAD DATA INFILE '/path_to_csv_folder/db.csv' INTO TABLE table1
     FIELDS TERMINATED BY ',' 
     ENCLOSED BY '"'
     ESCAPED BY '"'
     LINES TERMINATED BY '\n'
    IGNORE 1 LINES;
    

    Windows saved end of line as \r\n (i.e. CF LF) where as I was using \n. I was getting crazy why phpMyAdmin was able to import the file while I couldn't. Only when I open the file in notepadd++ and saw the end of file then I realized that mysql was unable to find any lines terminated symbol (and I guess it consider all the lines as input to the field; making it complain.)

    Anyway after making from \n to \r\n; it work like a charm.

    LOAD DATA INFILE '/path_to_csv_folder/db.csv' INTO TABLE table1
     FIELDS TERMINATED BY ',' 
     ENCLOSED BY '"'
     ESCAPED BY '"'
     LINES TERMINATED BY '\r\n'
    IGNORE 1 LINES;
    

提交回复
热议问题