简体   繁体   English

1900万行txt文件到sql

[英]19 million lines of txt files to sql

Hi My txt is format blabla,blabla,blabla,bla,bla I know PHP and I can parse each line and save it to the database, but this will take 31 hours according to my calculations.嗨,我的 txt 格式是 blabla,blabla,blabla,bla,bla 我知道 PHP 并且我可以解析每一行并将其保存到数据库中,但根据我的计算这需要 31 小时。 Is there an easier way?有没有更简单的方法?

Did you try using "import" feature?您是否尝试使用“导入”功能? Another option is to generate insert statements using a scripting language (language eg python) and saving it as a sql file then execute the sql file.另一种选择是使用脚本语言(例如 python)生成插入语句并将其保存为 sql 文件,然后执行 sql 文件。

If you comma-separated-values file is alyreay in right order (first column mathes your first value, and same for remaining values), then try someting like:如果您的逗号分隔值文件的顺序正确(第一列计算您的第一个值,其余值相同),然后尝试类似:

LOAD DATA INFILE '/path/to/my-file.csv' INTO TABLE my_db.my_table;

https://dev.mysql.com/doc/refman/8.0/en/load-data.html https://dev.mysql.com/doc/refman/8.0/en/load-data.html

Else, you need to first write an algorithm to rearrange your CSV file's content (line by line), then try above.否则,您需要先编写一个算法来重新排列 CSV 文件的内容(逐行),然后在上面尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM