How do I insert a large number of rows in MySQL?(如何在 MySQL 中插入大量行?)
问题描述
如何通过单个查询将例如 100 000 行插入 MySQL 表?
insert into $table values (1, a, b), (2, c, d), (3, e, f);这将执行 3 行的插入.根据需要继续达到 100,000.在进行 ETL 工作时,我会以这种方式处理大约 1,000 个块.
如果您的数据静态保存在文件中,则对其进行转换并使用 load data infile 将是最好的方法,但我猜您之所以问这个问题是因为您做了类似的事情.p>
还要注意其他人所说的关于限制查询长度的 max_allowed_packet 大小.
How do I insert for example 100 000 rows into MySQL table with a single query?
insert into $table values (1, a, b), (2, c, d), (3, e, f);
That will perform an insertion of 3 rows. Continue as needed to reach 100,000. I do blocks of ~1,000 that way when doing ETL work.
If your data is statically in a file, transforming it and using load data infile will be the best method, but I'm guessing you're asking this because you do something similar.
Also note what somebody else said about the max_allowed_packet size limiting the length of your query.
这篇关于如何在 MySQL 中插入大量行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 MySQL 中插入大量行?
基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
