現在、テキストファイルからテーブルに約 2,000 万行のデータをインポートしようとしています。その速度は遅すぎます (さらに 2000 万では十分ではありません)。
実際にプロセスを高速化する方法はありますか? ところで、phpmyadminから実行します...
<?php
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$selected = mysql_select_db("data",$dbhandle)
or die("Could not select data");
$handle = fopen ('text.txt', 'rt');
while (!feof ($handle))
{
ini_set('max_execution_time',10800);
$buffer = fgets($handle, 4096);
list($a,$b,$c)=explode(" ",$buffer);
$lol = explode(".",$c);
$rest = substr($c,-5,3);
$date = date('Y-m-d H:i:s');
if($rest == 'COM'){
echo $a." | ".$b." | ".$c."<br>";
$sqlquery = "INSERT INTO zonenet (date, domainname, dnstype, nameserver) VALUES('".$date."','".$a."','".$b."','".$c."')";
mysql_query($sqlquery,$dbhandle) or die(mysql_error());
}
else {
//$dnstype = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".",
// "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
$str = str_replace($lol[1],".NET",$lol[1]);
//$str = str_replace(end($lol),".NET",end($lol));
echo $a." | ".$b." | ".$lol[0]."".$str."<br>";
$sqlquery = "INSERT INTO zonenet (date, domainname, dnstype, nameserver) VALUES('".$date."','".$a."','".$b."','".$lol[0]."".$str."')";
mysql_query($sqlquery,$dbhandle) or die(mysql_error());
}
//dnstype reference @http://en.wikipeda.org/wiki/List_of_DNS_record_types
$sqlquery1 = "DELETE FROM zonenet WHERE dnstype NOT IN ('A', 'AAAA', 'AFSDB', 'APL', 'CAA', 'CERT', 'CNAME', 'DHCID'`enter code here`, 'DLV', 'DNAME', 'DNSKEY', 'DS', 'HIP', 'IPSECKEY', 'KEY', 'KX', 'LOC', 'MX', 'NAPTR', 'NS', 'NSEC', 'NSEC3', 'NSEC3PARAM', 'PTR', 'RRSIG', 'RP', 'SIG', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TA', 'TKEY', 'TLSA', 'TSIG', 'TXT')";
mysql_query($sqlquery1,$dbhandle) or die(mysql_error());
}
fclose ($handle);
//close the connection
mysql_close($dbhandle);
//$net=explode(".",$c);
//echo $a."-".$b."-".$c."<br>";
//
//
//mysql_query($sqlquery,$dbhandle) or die(mysql_error());
?>