当前位置:网站首页>The reason why data truncated for column 'xxx' at row 1 appears in the MySQL import file

The reason why data truncated for column 'xxx' at row 1 appears in the MySQL import file

2022-07-07 13:51:00 Full stack programmer webmaster

mysql When importing files, it is easy to see ”Data truncated for column ‘xxx’ at row x”, In the string xxx and x It refers to the specific number of columns and rows .

occasionally , This is because the data types do not correspond , Or the string length is not enough .

however , Often appear row 1 Just report a mistake , And I feel that there is nothing wrong with it .

This is often because windows Enter and change lines ”\r\n” setting , The following tests illustrate this .

I have one train.csv Data files for , I use python Save as after modification c.csv.

however , I use the same command to import them into mysql when ,train Can be imported ,c But it went wrong .

I change the line terminator from ”\n” Switch to ”\r\n” after , Successful import .

use notepad Open these two files , Will find train There is no new line , and c Then there is line feed .

This explanation train Only in Li ”\n”, therefore notepad Unrecognized line breaks , and c Inside, it is ”\r\n”.

But with python Generate c.csv When , The output is only ”\n”, This explanation python stay win It will automatically turn ”\n” become ”\r\n”.

The other thing is , except notepad Most of the outside win Under the editor , Both can recognize ”\n” And can recognize ”\r\n”.

So only use notepad To know what it is ”\n” still ”\r\n”, Or use winHex Wait for tools to see directly ascii code .

The final conclusion is , Note that the newline of this data file is ”\n” still ”\r\n”.

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113289.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071146403011.html