将海量数据插入Mysql数据库的最快方法 [英] Quickest way to Insert mass data Into Mysql database

查看:114
本文介绍了将海量数据插入Mysql数据库的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上有一个要插入MySQL数据库的100,000条记录的列表.

I actually have a list of 100,000 records which I'd like to insert into the MySQL database.

我试图用foreach和简单的INSERT INTO插入它们,但是即使插入100行也要花费很多时间.像是1秒/行.

I have tried to insert them with foreach and simple INSERT INTO however it took a lot of time to insert even 100 row. Like 1 second / row.

有什么方法可以更快地插入这些行吗?

IS there any method to insert these rows much faster?

推荐答案

使用一个多行INSERT语句比每行一个INSERT语句快. 这样可以减少对数据库的调用.

Using one INSERT statement with multiple rows is faster than one INSERT statement per row. This will reduce calls to the database.

示例:

 INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

这篇关于将海量数据插入Mysql数据库的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆