将大型xls文件导入mysql数据库

4

我想将大型 xlsx(电子表格文件)导入到MySQL数据库中。 我以前通过phpmyadmin完成了此操作,但是这个文件太大了(205000行)。

所以当我尝试使用phpmyadmin时,它花费了很长时间并且无法完成。

有什么最好且快速的方法可以将其导入到MySQL数据库中吗?

3个回答

6
您可以使用MySQL中的LOAD DATA命令来完成此操作:http://blog.tjitjing.com/index.php/2008/02/import-excel-data-into-mysql-in-5-easy.html
Save your Excel data as a csv file (In Excel 2007 using Save As)
Check the saved file using a text editor such as Notepad to see what it actually looks like, i.e. what delimiter was used etc.
Start the MySQL Command Prompt (I usually do this from the MySQL Query Browser – Tools – MySQL Command Line Client to avoid having to enter username and password etc.)
Enter this command:
LOAD DATA LOCAL INFILE ‘C:\\temp\\yourfile.csv’ INTO TABLE database.table FIELDS TERMINATED BY ‘;’ ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\r\n’ (field1, field2);
[Edit: Make sure to check your single quotes (') and double quotes (") if you copy and paste this code]
Done!

0
你可以尝试使用 Navicat MySQL。我曾经用 250MB+ 的 xlsx 文件进行过操作,Navicat 轻松处理而无需费力。
只需要确保你的 MySQL 已经配置为能够接收大量数据,方法是在你的 my.ini 文件中更改 max_allowed_packet 选项为较大的值,例如 128M。

0

Toad for MySQL(免费软件)将是另一个选择。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接