2

试图将一个小的 .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)
4

1 回答 1

5

尝试

LOAD DATA LOCAL INFILE 'c://petdata.txt'
  INTO TABLE `pet`
  FIELDS
    TERMINATED BY ','
  LINES
    TERMINATED BY '\n'
于 2012-06-19T11:10:34.613 回答