如何将excel文件导入MySQL数据库

2021-11-20 00:00:00 excel mysql

谁能解释一下如何将 Microsoft Excel 文件导入 MySQL 数据库?

Can any one explain how to import a Microsoft Excel file in to a MySQL database?

例如,我的 Excel 表格如下所示:

For example, my Excel table looks like this:

Country   |   Amount   |   Qty
----------------------------------
America   |   93       |   0.60

Greece    |   9377     |   0.80

Australia |   9375     |   0.80

推荐答案

  1. 将其导出为某种文本格式.最简单的可能是制表符分隔的版本,但 CSV 也可以.

  1. Export it into some text format. The easiest will probably be a tab-delimited version, but CSV can work as well.

使用加载数据功能.参见 http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Use the load data capability. See http://dev.mysql.com/doc/refman/5.1/en/load-data.html

向下看页面的一半,因为它会为制表符分隔数据提供一个很好的示例:

Look half way down the page, as it will gives a good example for tab separated data:

由 '\t' 结尾的字段由 '' 包围,由 '\' 转义

FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\'

检查您的数据.有时引用或转义会出现问题,您需要调整源代码、导入命令——或者通过 SQL 进行后处理可能更容易.

Check your data. Sometimes quoting or escaping has problems, and you need to adjust your source, import command-- or it may just be easier to post-process via SQL.

相关文章