从 CSV 导入 MySql

发布于 2024-11-25 07:31:16 字数 578 浏览 0 评论 0原文

我有一个包含三列的表,NODEID、X、Y。NODEID 是主键,它被设置为 INT(4) 以进行自动增量。我希望通过 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

等等...

I have a table with three columns, NODEID, X, Y. NODEID is the primary key and it is set as an INT(4) to be AUTOINCREMENT. I wish to add more data to this table by importing it from a CSV via the phpmyadmin import. Question:

  1. What would be the format of the CSV look like?
  2. Is this possible or is importing basically just to replace the whole data with the CSV?

As of now the CSV looks like:

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

etc...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗笺 2024-12-02 07:31:16

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

Change the SQL that phpmyadmin will run to this:

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

(You will only have to change the last line)
And your csv should look like

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

The last line tells MySQL to look for only those two columns of data and insert null for any other columns. The NULL value will be auto-incremented as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文