三、100 万数据性能测试
1.查看一下创建的表
MySQL> show create table t1;
+-------+--------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
注,我们先测试一下MyISAM引擎。
2.查看一下表结构
mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.01 sec)
3.下面插入数据100万行
(1).先插入10行数据
mysql> insert into t1 value (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+------+
10 rows in set (0.00 sec)
(2).下面我们正来继续插入数据
mysql> insert into t1 select * from t1;
Query OK, 1310720 rows affected (0.64 sec)
Records: 1310720 Duplicates: 0 Warnings: 0
mysql> select count(*) from t1;
+----------+
| count(*) |
+----------+
| 2621440 |
+----------+
1 row in set (0.00 sec)
注,大家可以看到插入100万行的数据只用了0.64秒,查询几乎不花时间。
4.下面我们来新建一下t2表,并设置默认引擎为InnoDB;
mysql> CREATE TABLE `t2` ( id int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.36 sec)
mysql> show tables;
+----------------+
| Tables_in_mydb |
+----------------+
| t1 |
| t2 |
+----------------+
2 rows in set (0.00 sec)
mysql> show create table t2;
+-------+--------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> desc t2;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.01 sec)
5.下面我们插入数据并进行查询测试
12345678910 mysql> insert into t2 select * from t2;
Query OK, 1310720 rows affected (13.03 sec)
Records: 1310720 Duplicates: 0 Warnings: 0
mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
| 2621440 |
+----------+
1 row in set (1.20 sec)
6.总结
(1).MyISAM 引擎
插入100多万行数据花费的时间为 0.64 秒。
用select count(*) from t1 命令查询的时间为 0.00 秒。
(2).InnoDB 引擎
插入100多万行数据花费的时间为 13.03 秒。
用select count(*) from t1 命令查询的时间为 1.20 秒。
下面我们继续测试……
四、200 万数据性能测试
1.t1表插入并查询数据
mysql> insert into t1 select * from t1;
Query OK, 2621440 rows affected (1.23 sec)
Records: 2621440 Duplicates: 0 Warnings: 0
mysql> select count(*) from t1;
+----------+
| count(*) |
+----------+
| 5242880 |
+----------+
1 row in set (0.00 sec)
2.t2表插入并查询数据
mysql> insert into t2 select * from t2;
Query OK, 2621440 rows affected (26.32 sec)
Records: 2621440 Duplicates: 0 Warnings: 0
mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
| 5242880 |
+----------+
1 row in set (2.08 sec)
3.总结
(1).MyISAM 引擎
插入200多万行数据花费的时间为 1.23 秒。
用select count(*) from t1 命令查询的时间为 0.00 秒。
(2).InnoDB 引擎
插入200多万行数据花费的时间为 26.32 秒。
用select count(*) from t1 命令查询的时间为 2.08 秒。
