当前位置:网站首页>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
边栏推荐
- 干货|总结那些漏洞工具的联动使用
- Navicat运行sql文件导入数据不全或导入失败
- Deep understanding of array related problems in C language
- Xshell connection server changes key login to password login
- Read PG in data warehouse in one article_ stat
- QQ medicine, Tencent ticket
- 室内ROS机器人导航调试记录(膨胀半径的选取经验)
- 2022-7-7 Leetcode 34. Find the first and last positions of elements in a sorted array
- 2022-7-6 beginner redis (I) download, install and run redis under Linux
- 如何让join跑得更快?
猜你喜欢
xshell连接服务器把密钥登陆改为密码登陆
[dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
OSI seven layer model
Leetcode simple question sharing (20)
Scripy tutorial classic practice [New Concept English]
Milkdown control icon
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
QQ的药,腾讯的票
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
随机推荐
move base参数解析及经验总结
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
Read PG in data warehouse in one article_ stat
【等保】云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
2022-7-7 Leetcode 844. Compare strings with backspace
Leetcode simple question sharing (20)
干货|总结那些漏洞工具的联动使用
高等数学---第八章多元函数微分学1
Split screen bug notes
2022-7-7 Leetcode 844.比较含退格的字符串
[etc.] what are the security objectives and implementation methods that cloud computing security expansion requires to focus on?
记一次 .NET 某新能源系统 线程疯涨 分析
高等數學---第八章多元函數微分學1
Distributed transaction solution
Error lnk2019: unresolved external symbol
得物客服热线的演进之路
118. Yanghui triangle
[high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
Centso7 OpenSSL error Verify return code: 20 (unable to get local issuer certificate)
【日常训练--腾讯精选50】231. 2 的幂