关于LOAD DATA LOCAL INFILE

ihelloworld 2011-12-30 01:47:56
有这样一个文件users.txt

user001中文 e10adc3949ba59abbe56e057f20f883e NULL
user002 e10adc3949ba59abbe56e057f20f883e NULL
user003 e10adc3949ba59abbe56e057f20f883e NULL
user004 e10adc3949ba59abbe56e057f20f883e NULL
user005 e10adc3949ba59abbe56e057f20f883e NULL
user006 e10adc3949ba59abbe56e057f20f883e NULL
user007 e10adc3949ba59abbe56e057f20f883e NULL
user008 e10adc3949ba59abbe56e057f20f883e NULL
user009 e10adc3949ba59abbe56e057f20f883e NULL
user010 e10adc3949ba59abbe56e057f20f883e NULL
user008 e10adc3949ba59abbe56e057f20f883e NULL
user009 e10adc3949ba59abbe56e057f20f883e NULL
user010 e10adc3949ba59abbe56e057f20f883e NULL

用下面的语句导入到users表中,

LOAD DATA LOCAL INFILE "D:/users.txt"
INTO TABLE users
FIELDS TERMINATED BY "\t" ENCLOSED BY ""
LINES TERMINATED BY "\n" STARTING BY "" (username, password, avatar)


但是有个问题,被导入的数据,其中NULL值,被做为字符串"NULL"导了进去,
有没有办法把NULL这一列做为mysql的NULL,而不是字符串null导入?
...全文
105 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2011-12-30
  • 打赏
  • 举报
回复
关于LOAD DATA LOCAL INFILE [ :40分]
ihelloworld (ihelloworld)
'截至2011-12-30 13:47:56 用户结帖率0.00%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html

8、如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖


ACMAIN_CHM 2011-12-30
  • 打赏
  • 举报
回复
LOAD DATA LOCAL INFILE "D:/users.txt"
INTO TABLE users
FIELDS TERMINATED BY "\t" ENCLOSED BY ""
LINES TERMINATED BY "\n" STARTING BY ""
(username, password, @x)
set avatar=if(@x='NULL',null,@x);
ihelloworld 2011-12-30
  • 打赏
  • 举报
回复
来人呐~~
ihelloworld 2011-12-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rucypli 的回复:]

更新呗


update tb set col1=xxx where col1 = 'NULL'
update tb set col2=xxx where col2 = 'NULL'
update tb set col3=xxx where col3 = 'NULL'
[/Quote]

不是啊,users.txt是程序自动生成的,内容不是己知的~~
rucypli 2011-12-30
  • 打赏
  • 举报
回复
更新呗


update tb set col1=xxx where col1 = 'NULL'
update tb set col2=xxx where col2 = 'NULL'
update tb set col3=xxx where col3 = 'NULL'
wwwwb 2011-12-30
  • 打赏
  • 举报
回复
文本没有NULL,1列1列替换吧
ihelloworld 2011-12-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wwwwb 的回复:]

导入后,再UPDATE 此字段为NULL不行?
[/Quote]
不行啊, 那么多列,不知道是哪个列有null值啊,update也没法写啊
wwwwb 2011-12-30
  • 打赏
  • 举报
回复
导入后,再UPDATE 此字段为NULL不行?

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧