innodb_file_per_table是否打开对创建或删除表的影响

来源:互联网 发布:工资管理系统 数据库 编辑:程序博客网 时间:2024/06/07 18:31

本文将测试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结果:

  • With innodb_file_per_table=ON
    • Schema and table creation = 2m12.117s
    • Schema drops = 0m10.654s
  • With innodb_file_per_table=OFF
    • Schema and table creation = 1m15.462s
    • Schema drops = 0m6.990s

从上面看innodb_file_per_table=OFF情况下,创建和删除表的确节省一点时间。


上面测试的都是空表,如果表里面有大量数据的话,innodb_file_per_table = ON情况下删除InnoDB存储引擎的表耗用时间应该更长。



0 0
原创粉丝点击