通过phpmyadmin在Mysql中加载CSV数据

发布于 2024-10-08 07:13:47 字数 299 浏览 0 评论 0原文

我有一个像这样的 Excel 文件:

      a
1 word1 : mean1
2 word2 : mean2
3 word3 : mean3
.
.

我已将其保存为 cvs 文件。我可以将这个cvs文件与这个表一起导入到mysql吗?

id   word   mean
1    word1  mean1
2    word2  mean2

我尝试过使用 LOAD DATA 的 CSV 和以 : 结尾的字段,并且仅导入 ids。 提前致谢

I have a excel file like this:

      a
1 word1 : mean1
2 word2 : mean2
3 word3 : mean3
.
.

and I have saved this a cvs file. Can I import this cvs file to mysql with this table?

id   word   mean
1    word1  mean1
2    word2  mean2

I have tried CSV using LOAD DATA with Fields terminated by : and only ids imported.
Thanks in advance

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

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

发布评论

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

评论(3

戏舞 2024-10-15 07:13:47

制作 Excel 文件的副本。在副本中:

  • 删除其中包含 a 的行。
  • 删除带有冒号的列。
  • 插入标题行,以便
    电子表格看起来像您的表格
    想要在 MySQL 中。

将副本导出为 CSV。

在 phpMyAdmin 中创建数据库。

在 phpMyAdmin 的导入页面上使用这些设置。

导入的文件格式部分中,选择 CSV。

选项部分中,设置以下内容:

  • 字段终止于 ,(毕竟,它
    是一个以逗号分隔的 CSV 文件
    值)
  • 由“”括起来的字段
  • 第一行中的列名称 选中

要导入的文件部分中,浏览查找将文件保存到您的计算机上,无论您将其保存在何处,

请单击前往按钮。

Make a copy of your Excel file. In the copy:

  • delete the row with the a in it.
  • delete the column with the colons.
  • insert a headings row, so that the
    spreadsheet looks like the table you
    want in MySQL.

Export the copy to CSV.

Create a database in phpMyAdmin.

Use these settings on the Import page of phpMyAdmin.

In the Format of imported file section, select CSV.

In the Options section, set the following:

  • Fields terminated by , (after all, it
    is a CSV file with comma separated
    values)
  • Fields enclosed by "
  • Column names in first row checked

In the File to import section, browse for the file on your computer, wherever you saved it.

Click the Go button.

诠释孤独 2024-10-15 07:13:47

最好的选择是一个简短的 PHP 脚本,如下所示:

<?php

$fp = fopen('path-to-csv.csv','r');

while ($row = fgetcsv($fp)) {

$sql = "INSERT INTO `table` (`col1`,`col2`) VALUES ('{$row[0]}','{$row[1]')";
mysql_query($sql);

}

?>

Your best bet is a short PHP script, something like this:

<?php

$fp = fopen('path-to-csv.csv','r');

while ($row = fgetcsv($fp)) {

$sql = "INSERT INTO `table` (`col1`,`col2`) VALUES ('{$row[0]}','{$row[1]')";
mysql_query($sql);

}

?>
你又不是我 2024-10-15 07:13:47

使用 phpmyadmin

选择导出为 Excel 2007 XLSX Workbook

选中“另存为文件”复选框

Put fields names in the first row

。就这样。

use phpmyadmin

choose export as Excel 2007 XLSX Workbook

check the checkbox saying

Put fields names in the first row

Save as file. Thats all.

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