秒速插入百万测试数据MYSQL,提供你玩玩大数据!

1.用PHP代码循环把要插入的数据存入文件

//随机字符串

function getRandChar($length){
$str = null;
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($strPol)-1;
for($i=0;$i<$length;$i++){
$str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
}

return $str;
}

function get_customers()
{
$t=mktime(); 
set_time_limit(1000); 
$myFile="e:/insert.sql"; 
$fhandler=fopen($myFile,'wb'); 
if($fhandler){ 
$i=0; 
while($i<1000000)//1,000,000 
{
$firstname = $this->getRandChar(5);//放到类里面使用
$email = $firstname.'@qq.com';
$password = sha1($firstname);
$sql="$firstname\t$firstname\t$email\t$password"; //注意字段数据之间用\t分隔
$i++; 
fwrite($fhandler,$sql."\r\n"); 
} 
echo"写入成功,耗时:",mktime()-$t; 
}
exit;

}

  

2.运行LOAD DATA local INFILE在MYSQL查询器里面读取写入数据的文件,就可以秒如数据库百万数据了

 LOAD DATA local INFILE 'e:/insert.sql' INTO TABLE gc_customers(`firstname`, `lastname`, `email`, `password`);

  

 

posted @ 2015-05-25 16:55  feimengv  阅读(265)  评论(0编辑  收藏  举报