【发布时间】:2019-05-11 02:58:36
【问题描述】:
我有一个日志文件,perl 脚本获取日志文件并转录日志文件,我想在一次提交中发送所有行(八千行)
我的脚本:
# Connect to the database.
my $dbh = DBI->connect(
"DBI:mysql:database=DB;host=>IP",
"hostname", 'password',
{'RaiseError' => 1,'AutoCommit'=> 0}
);
open (FILE, 'file.log');
while (<FILE>) {
($word1, $word2, $word3, $word4, $word5, $word6, $word7, $word8, $word9, $word10, $word11, $word12, $word13, $word14) = split(" ");
$word13 =~ s/[^\d.]//g;
if ($word2 eq "Feb") {
$word2 = "02"
}
print "'$word5-$word2-$word3 $word4', $word11, $word13 \n";
eval {
#on peut utiliser insert mais il y aura des doublons et ici on est dans une table unique
my $sth = $dbh->prepare("INSERT INTO `test_query` (time, cstep, time_in_seconde) VALUES('$word5-$word2-$word3 $word4', $word11, $word13);");
#print $sth->rows . " rows found.\n";
#$sth->finish;
# do inserts, updates, deletes, queries here
#$sth->execute() or die "execution failed: $dbh->errstr()";
$sth->execute() or die "execution failed: $dbh->errstr()";
$dbh->commit();
};
### If something went wrong...
}
}
$dbh->disconnect();
谢谢
【问题讨论】:
-
所以
Feb被转换为02,但是March 呢? -
有什么问题或疑问?
-
我的问题是如何一次放千行
-
不知道为什么它被关闭了,因为不清楚。 OP 询问如何将多行添加为一个事务,答案涵盖了这一点。
标签: linux windows perl sql-insert query-performance