MySQL LOAD DATA INFILE Data too long for column exception

a 夏天 提交于 2019-12-06 16:41:55

Add CHARACTER SET utf8 parameter to LOAD DATA INFILE... statement:

LOAD DATA INFILE 'MyFile.csv'
 INTO TABLE `dbname`.`tablename`
 CHARACTER SET utf8
 FIELDS TERMINATED BY '\t' ENCLOSED BY '"'
 LINES TERMINATED BY '\r\n';

As stated in documentation it specifies which character set is used in the file:

The character set indicated by the character_set_database system variable is used to interpret the information in the file. SET NAMES and the setting of character_set_client do not affect interpretation of input. If the contents of the input file use a character set that differs from the default, it is usually preferable to specify the character set of the file by using the CHARACTER SET clause, which is available as of MySQL 5.1.17.

If it is not specified then gets default value, for example latin1 and each utf-8 byte is interpreted as character. Because some utf-8 encoded characters has more than one byte you got longer strings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!