gpt4 book ai didi

从 CSV 导入 MySql

转载 作者:行者123 更新时间:2023-11-29 03:11:58 27 4
gpt4 key购买 nike

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

  1. CSV 的格式是什么样的?
  2. 这是可能的还是导入基本上只是为了用 CSV 替换整个数据?

截至目前,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

等...

最佳答案

将 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 值将按预期自动递增。

关于从 CSV 导入 MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6756726/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com