当前位置:网站首页>mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
2022-07-07 11:48:00 【全栈程序员站长】
mysql导入文件的时候很容易出现”Data truncated for column ‘xxx’ at row x”,其中字符串里的xxx和x是指具体的列和行数.
有时候,这是因为数据类型的不对应,或者字符串长度不够而造成的.
但是,经常出现row 1就报错,并且感觉它没什么不对的样子.
这往往是因为windows的回车换行”\r\n”作怪,下面的测试说明了这种情况.
我有一个train.csv的数据文件,我用python修改后保存为c.csv.
但是,我用相同的命令把它们导入到mysql时,train能导入,c却出错.
我把行结束符从”\n”换成”\r\n”后,导入成功.
用notepad打开这两个文件,会发现train根本没有换行,而c则有换行.
这说明train里只有”\n”,因此notepad无法识别到换行,而c里则是”\r\n”.
然而用python生成c.csv的时候,输出只有”\n”,这说明python在win下会自动把”\n”变成”\r\n”.
还有一点是,除了notepad外的大部分win下的编辑器,都既能识别”\n”又能识别”\r\n”.
因此只有用notepad才能知道到底是”\n”还是”\r\n”,或者用winHex等工具直接看ascii码.
最后的结论是,注意这个数据文件的换行到底是”\n”还是”\r\n”.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113289.html原文链接:https://javaforall.cn
边栏推荐
- Getting started with MySQL
- Navicat run SQL file import data incomplete or import failed
- 社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
- PostgreSQL array type, each splice
- How far can it go to adopt a cow by selling the concept to the market?
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- Cinnamon taskbar speed
- Evolution of customer service hotline of dewu
- Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
- 华为镜像地址
猜你喜欢
Flink | multi stream conversion
存储过程的介绍与基本使用
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
Introduce six open source protocols in detail (instructions for programmers)
LeetCode简单题分享(20)
Esp32 construction engineering add components
SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
Help tenants
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
Storage principle inside mongodb
随机推荐
高等數學---第八章多元函數微分學1
Simple and easy-to-use code specification
10 pictures open the door of CPU cache consistency
现在网上开户安全么?那么网上开户选哪个证券公司?
mysql 局域网内访问不到的问题
PostgreSQL array type, each splice
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
Shell batch file name (excluding extension) lowercase to uppercase
Oracle advanced (V) schema solution
一文读懂数仓中的pg_stat
Mongodb meets spark (for integration)
High end for 8 years, how is Yadi now?
Build a secure and trusted computing platform based on Kunpeng's native security
DID登陆-MetaMask
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
Write it down once Net a new energy system thread surge analysis
靠卖概念上市,认养一头牛能走多远?
The delivery efficiency is increased by 52 times, and the operation efficiency is increased by 10 times. See the compilation of practical cases of financial cloud native technology (with download)
得物客服热线的演进之路