MySQL 使用 phpMyAdmin 导入大型 csv 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11430223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import large csv file using phpMyAdmin
提问by duracell
I have a csv file, a big one, 30 000 rows. I've tried to import it using LOAD file etc.. from the terminal, as I found on google, but it didn't work. It was making the import but my table got to 30 000 rows of NULL cells.
我有一个 csv 文件,很大,有 30 000 行。我尝试使用 LOAD 文件等从终端导入它,正如我在谷歌上找到的那样,但它没有用。它正在进行导入,但我的表有 30 000 行 NULL 单元格。
After that I tried phpMyAdmin and there I found out that my csv was too big. I've split it in 5 using CSV Splitter. I've made the import for the first file. Everything went great. Than I tried to import the second one, but I got thos error:
之后我尝试了 phpMyAdmin,在那里我发现我的 csv 太大了。我已经使用 CSV Splitter 将它分成了 5 个。我已经导入了第一个文件。一切都很顺利。比我试图导入第二个,但我得到了错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) in C:\xampp\phpMyAdmin\libraries\import\csv.php on line 370
致命错误:第 370 行 C:\xampp\phpMyAdmin\libraries\import\csv.php 中允许的内存大小为 134217728 字节(试图分配 35 个字节)
or 1064 error sometimes.
或 1064 错误有时。
Do you know why and how can I solve it? Thank you.
你知道为什么以及我该如何解决吗?谢谢你。
回答by Packet Tracer
Increase your php's memory limit and script time, that's beacause your executing the mysql instruction through the php server.
增加你的php的内存限制和脚本时间,这是因为你通过php服务器执行mysql指令。
Check your php.ini file for this vars:
检查您的 php.ini 文件是否有此变量:
memory_limit
max_execution_time
But anyway I would do it through the mysql client (terminal), check mysql doc
但无论如何我都会通过 mysql 客户端(终端)来完成,检查 mysql doc
LOAD DATA LOCAL INFILE '/path/to/your/csv/file/csv_file.csv' INTO TABLE database_name.table_name FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Mysql Documentation - Load Data Infile SyntaxPHP Documentation - Ini core settings
回答by David
I got this problem when trying to import a large file using phpMyAdmin, and am also unable to use the command in the version which I am using. To solve this I used this CSV editorand split the file into smaller files. Worked fine when I imported each chunk separately.
我在尝试使用 phpMyAdmin 导入大文件时遇到了这个问题,并且在我使用的版本中也无法使用该命令。为了解决这个问题,我使用了这个 CSV 编辑器并将文件拆分为较小的文件。当我分别导入每个块时工作正常。