【问题标题】:Efficient multiple row inserts in mysql [duplicate]mysql中的高效多行插入[重复]
【发布时间】:2012-10-16 19:24:17
【问题描述】:

可能重复:
Which is faster: multiple single INSERTs or one multiple-row INSERT?

在翻阅一本关于 mysql 的书时,我发现了两种在数据库中插入行的方法。

Method 1 

INSERT INTO tableName (col1, col2, col3) VALUES('a', 'b', 'c');
INSERT INTO tableName (col1, col2, col3) VALUES('d', 'b', 'c');
INSERT INTO tableName (col1, col2, col3) VALUES('e', 'b', 'c');

Method 2

INSERT INTO tableName (col1, col2, col3) VALUES('a', 'b', 'c'), ('d', 'b', 'c'), ('e', 'b', 'c');

第二种方法比第一种更有效吗?还是只是简单地多次调用Method 1

【问题讨论】:

标签: mysql performance insert


【解决方案1】:

第二种效率更高。

第一种方法在您每次要插入一行时创建一个连接,而第二种方法使用单个连接来插入所有行。但是,max_allowed_packet 限制了客户端的 INSERT 语句的长度。

【讨论】:

  • 你能简单介绍一下 max_allowed_pa​​cket 的大小吗?它是用户可配置的吗?
  • @PrashantSingh This 主题解释了它控制的内容,this 主题解释了如何配置设置。
猜你喜欢
  • 2018-09-08
  • 1970-01-01
  • 2016-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-24
  • 2014-02-10
  • 2017-09-26
相关资源
最近更新 更多