尝试将一个小的.txt文件加载到mysql中,但是除了null和\ n之外,我的所有数据都显示在一个字段中。
这是数据布局:
Fluffy,Harold,cat,f,1993-02-04,null \N
Claws,Gwen,cat,m,1994-03-17,null \N
Buffy,Harold,dog,f,1989-05-13,null \N
Fang,Benny,dog,m,1990-08-27,null \N
Bowser,Diane,dog,m,1995-08-31,1998-07-29 \n
Chirpy,Gwen,bird,f,1998-09-11,null \N
Whistler,Gwen,bird,null,1997-12-09,null \N
Slim,Benny,snake,m,1996-04-29,null \N
我使用的命令是:LOAD DATA LOCAL INFILE"c://petdata.txt" INTO TABLE pet;
这似乎是有效的,因为数据进入表格但格式错误。
这是我的输出
mysql> SELECT*FROM pet;
+----------------------+-------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+----------------------+-------+---------+------+------------+-------+
| Bowser,Diane,dog,m,1 | | | | 0000-00-00 | NULL |
| Buffy,Harold,dog,f,1 | | | | 0000-00-00 | NULL |
| Chirpy,Gwen,bird,f,1 | | | | 0000-00-00 | NULL |
| Claws,Gwen,cat,m,199 | | | | 0000-00-00 | NULL |
| Fang,Benny,dog,m,199 | | | | 0000-00-00 | NULL |
| Fluffy,Harold,cat,f, | | | | 0000-00-00 | NULL |
| Slim,Benny,snake,m,1 | | | | 0000-00-00 | NULL |
| Whistler,Gwen,bird,n | | | | 0000-00-00 | NULL |
+----------------------+-------+---------+------+------------+-------+
8 rows in set (0.00 sec)
答案 0 :(得分:5)
尝试
LOAD DATA LOCAL INFILE 'c://petdata.txt'
INTO TABLE `pet`
FIELDS
TERMINATED BY ','
LINES
TERMINATED BY '\n'