从CSV导入MySql

时间:2011-07-20 03:35:11

标签: mysql phpmyadmin

我有一个包含三列的表,NODEID,X,Y。NODEID是主键,它被设置为INT(4)为AUTOINCREMENT。我希望通过phpmyadmin导入从CSV导入更多数据到此表。问题:

  1. CSV的格式是什么样的?
  2. 这是可能还是导入基本上只是用CSV替换整个数据?
  3. 截至目前,CSV看起来像:

    1,-105.057578,39.785603
    2,-105.038646,39.771132
    3,-105.013045,39.771727
    5,-105.045721,39.762055
    6,-105.031777,39.76206
    7,-105.046015,39.72835
    8,-105.029796,39.728304
    10,-104.930863,39.754579
    11,-104.910624,39.754644
    13,-104.930959,39.74367
    16,-105.045802,39.685253
    17,-105.032149,39.688557
    18,-105.060891,39.657622
    20,-105.042257,39.644086
    
    等等......

1 个答案:

答案 0 :(得分:1)

将phpmyadmin将运行的SQL更改为:

LOAD DATA INFILE '*FILEPATH*'
INTO TABLE *table*
(X, Y);

(你只需要改变最后一行) 你的csv应该看起来像

-105.057578,39.785603
-105.038646,39.771132
-105.013045,39.771727
-105.045721,39.762055
-105.031777,39.76206
-105.046015,39.72835

最后一行告诉MySQL只查找这两列数据,并为任何其他列插入null。 NULL值将按预期自动递增。