使用perl批量插入mysql DB表

使用perl批量插入mysql DB表,mysql,perl,bulkinsert,dbi,dbd,Mysql,Perl,Bulkinsert,Dbi,Dbd,我使用一个简单的perl脚本在mysql DB表中生成数百万行。我在脚本中使用perl DBI和DBD::mysql。下面是示例代码 my $dbh = DBI->connect(<DB INFO>); my $sth; my $insert_com = "INSERT INTO TAB1 VALUES(?,?,?,?,?)"; for (1..50000000){ $sth = $dbh->prepare($insert_com); $sth->ex

我使用一个简单的perl脚本在mysql DB表中生成数百万行。我在脚本中使用perl DBI和DBD::mysql。下面是示例代码

my $dbh = DBI->connect(<DB INFO>);
my $sth;
my $insert_com = "INSERT INTO TAB1 VALUES(?,?,?,?,?)";
for (1..50000000){

   $sth = $dbh->prepare($insert_com);
   $sth->execute(<val1>,<val2>,<val3>,<val4>,<val5>);

}
my$dbh=DBI->connect();
我的$某物;
my$insert_com=“插入表1值(?,,,,?,?)”;
对于(1..50000000){
$sth=$dbh->prepare($insert_com);
$sth->execute(,,,);
}
根据上面的代码,我认为循环的每次迭代都会发送一个提交。 我的问题是,是否有可能每n次迭代发送一次提交?i、 e在向表中插入n行后提交。如果可能的话,有人能告诉我怎么做吗。提前谢谢。干杯…

您必须将“自动提交”设置为零:

$dbh = DBI->connect($dsn, $user, $password,
                      { RaiseError => 1, AutoCommit => 0 });
并调用所有n行
$dbh->commit()

有关更多详细信息,请参阅。

Take`$sth=$dbh->prepare($insert_com);`语句可能重复循环