mysql中Load Data记录换行问题的解决方法
网络编程 2021-07-05 15:27www.168986.cn编程入门
有关mysql中Load Data记录换行的问题的解决方法, 需要的朋友可以参考下
问题是这样的:
表persons有两个字段: id和name
文本文档persons.txt中内容(其中每行字段之间用tab分割):
1 Bush
2 Carter
3 Bush
在mysql命令行下使用 load data local infile “persons.txt” into table persons 导入数据到persons表中。
导入后查看persons表的数据,与persons.txt的内容一致。但是使用语句
select distinct name from persons
查询,结果中Bush出现了两次(正常结果应该是Bush只出现一次)。
原因分析:
经过分析,发现原因是windows下换行符为"\r\n",而mysql在load data时默认使用"\n"来切割每行记录,导致插入到表中前两条记录的name字段末尾多插入了不可见字符"\r";也就是说使用distinct关键字查询出来的两个Bush中,第一个词尾有回车符"\r”,而第二个词尾没有。
说明:
1. mysql默认使用tab来分割每行的字段。
2. 因为linux下换行符为"\n",所以在linux下不会出现上述问题。
修改方法:
只要在导入数据时指定以"\r\n"来换行就可以了。
修改后的导入数据语句为:
代码如下:
load data local infile “persons.txt” into table persons
lines terminated by “\r\n”;
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程