本文将测试innodb_file_per_table打开或者关闭后对创建或删除表所耗用时间的影响。
测试环境搭建:
在MySQL数据库中创建16个库并且每个库中创建100张InnoDB存储引擎的表(空表):
[root@mysqlmaster data]# time $(for db in {1..16};
do mysql -e "create database bench$db";
$(for tb in {1..100}; do $(mysql bench$db -e "create table tab${tb} (i int) engine=innodb"); done) & done)
另外打开一个MySQL客户端终端,可以看到如下的内容:
表都创建好后,并行执行删除schema的操作。
下面将比较innodb_file_per_table的值为ON和OFF的情况:
1) innodb_file_per_table = ON的情况:
创建表
[root@mysqlmaster data]# time $(for db in {1..16};
> do mysql -e "create database bench$db";
> $(for tb in {1..100}; do $(mysql bench$db -e "create table tab${tb} (i int) engine=innodb"); done) & done)
real 2m12.117s
user 0m0.120s
sys 0m0.774s
删除表
[root@mysqlmaster data]# time $(for db in {1..16};
> do mysql -e "drop database bench${db}" & done)
real 0m10.654s
user 0m0.012s
sys 0m0.080s
2) innodb_file_per_table = OFF的情况:
创建表
[root@mysqlmaster ~]# time $(for db in {1..16};
> do mysql -e "create database bench$db";
> $(for tb in {1..100}; do $(mysql bench$db -e "create table tab${tb} (i int) engine=innodb"); done) & done)
real 1m15.462s
user 0m0.147s
sys 0m0.367s
删除表
[root@mysqlmaster ~]# time $(for db in {1..16};
> do mysql -e "drop database bench${db}" & done)
real 0m6.990s
user 0m0.000s
sys 0m0.018s
innodb_file_per_table ON vs OFF结果:
从上面看innodb_file_per_table=OFF情况下,创建和删除表的确节省一点时间。