上一次修改时间:2015-11-11 14:43:07

mysql数据插入测试

  1. 数据表引擎为InnoDB,一次用PHP插入100W万条随机数据,PHP的执行时间如下:

DROP TABLE IF EXISTS `test1`;
CREATE TABLE `test1` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
<?php
/*
 * PHP环境设置
 */
header("Content-type: text/html; charset=utf-8"); 
ini_set('memory_limit', '1536M');
ini_set('max_execution_time', 0);
//数据库连接
$link = mysql_connect('192.168.0.103','root','001020');
mysql_select_db('test');
$t1 = microtime(true);
for($i=0; $i<100; $i++){
    $data = '';
    for($j=0; $j<10000; $j++){
        $data .= "('','".rand(1,10000000)."'),";
    }
    $sql_temp = "INSERT INTO test1 VALUES $data";
    $sql = substr($sql_temp, 0, (strlen($sql_temp)-1));
    mysql_query($sql);
}
$t2 = microtime(true);
echo '文件耗时'.round($t2-$t1,3).'秒';

2.