MySQL5.6开始可以使用独立表空间, innodb_file_per_table=1
发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,MySQL5.6开始可以使用独立表空间: MySQL5.6 innodb_file_per_table=1 #使用独立表空间,动态参数。(5.6默认OFF,5.7默认ON)1、drop/truncat
千家信息网最后更新 2026年10月31日MySQL5.6开始可以使用独立表空间, innodb_file_per_table=1MySQL5.6开始可以使用独立表空间: MySQL5.6 innodb_file_per_table=1 #使用独立表空间,动态参数。(5.6默认OFF,5.7默认ON)
1、drop/truncate table方式操作表空间能自动回收(磁盘空间)
1)、创建procedure,循环insert一定量数据 ##use test ##drop procedure pro1;
DELIMITER // create procedure pro1() begin declare i int; set i=1; while i<100000 do insert into test.cc(id,name) values(i, "aa"); set i=i+1; end while; end;//
2)、调用procedure : mysql> call pro1();
3)、查看表大小、数据量: select table_name, (data_length+index_length)/1024/1024 as total_mb, table_rows from information_schema.tables where table_schema='test' and table_name='CC';
+------------+------------+------------+ | table_name | total_mb | table_rows | +------------+------------+------------+ | cc | 3.51562500 | 100246 | +------------+------------+------------+ 1 row in set (0.31 sec)
4)、truncate清表: mysql> truncate table test.cc; Query OK, 0 rows affected (0.73 sec)
5)、再次查看表空间已经回收:
cc.ibd 由 11264KB 回收到96KB 。
mysql> select table_name, (data_length+index_length)/1024/1024 as total_mb, table_rows -> from information_schema.tables where table_schema='test' and table_name='CC'; +------------+------------+------------+ | table_name | total_mb | table_rows | +------------+------------+------------+ | cc | 0.01562500 | 0 | +------------+------------+------------+ 1 row in set (0.00 sec)
mysql>
mysql> select version(); +------------+ | version() | +------------+ | 5.7.11-log | +------------+ 1 row in set (0.08 sec)
mysql>
注:drop table test.cc ; 物理文件cc.ibd也会同时被删除。
2、独立表空间下,可以自定义表的存储位置,(有时将部分热表放在不同的磁盘可有效地提升IO性能)
create table test(id int) data directory='c:/software'; create table test1(id int,name varchar(20),primary key (id)) data directory='c:/software';
3、独立表空间下,可以回收表空间碎片(比如一个非常大的delete操作之后释放的空间)
1)创建测试表
DELIMITER // create procedure pro_test1() begin declare i int; set i=1; while i<10000 do insert into test.test1(id,name) values(i, "aa"); set i=i+1; end while; end;//
##call pro_test1();
表大小:test1.ibd 368KB
2)delete后表大小: mysql> delete from test1; test1.ibd 384KB
3)回收表空间 mysql> alter table test1 engine=innodb; test1.ibd 96KB
mysql> select table_name, (data_length+index_length)/1024/1024 as total_mb, table_rows from information_schema.tables where table_schema='test' and table_name='TEST1';
+------------+------------+------------+
| table_name | total_mb | table_rows |
+------------+------------+------------+
| test1 | 0.01562500 | 0 |
+------------+------------+------------+
1 row in set (0.00 sec)
1、drop/truncate table方式操作表空间能自动回收(磁盘空间)
1)、创建procedure,循环insert一定量数据 ##use test ##drop procedure pro1;
DELIMITER // create procedure pro1() begin declare i int; set i=1; while i<100000 do insert into test.cc(id,name) values(i, "aa"); set i=i+1; end while; end;//
2)、调用procedure : mysql> call pro1();
3)、查看表大小、数据量: select table_name, (data_length+index_length)/1024/1024 as total_mb, table_rows from information_schema.tables where table_schema='test' and table_name='CC';
+------------+------------+------------+ | table_name | total_mb | table_rows | +------------+------------+------------+ | cc | 3.51562500 | 100246 | +------------+------------+------------+ 1 row in set (0.31 sec)
4)、truncate清表: mysql> truncate table test.cc; Query OK, 0 rows affected (0.73 sec)
5)、再次查看表空间已经回收:
cc.ibd 由 11264KB 回收到96KB 。
mysql> select table_name, (data_length+index_length)/1024/1024 as total_mb, table_rows -> from information_schema.tables where table_schema='test' and table_name='CC'; +------------+------------+------------+ | table_name | total_mb | table_rows | +------------+------------+------------+ | cc | 0.01562500 | 0 | +------------+------------+------------+ 1 row in set (0.00 sec)
mysql>
mysql> select version(); +------------+ | version() | +------------+ | 5.7.11-log | +------------+ 1 row in set (0.08 sec)
mysql>
注:drop table test.cc ; 物理文件cc.ibd也会同时被删除。
2、独立表空间下,可以自定义表的存储位置,(有时将部分热表放在不同的磁盘可有效地提升IO性能)
create table test(id int) data directory='c:/software'; create table test1(id int,name varchar(20),primary key (id)) data directory='c:/software';
3、独立表空间下,可以回收表空间碎片(比如一个非常大的delete操作之后释放的空间)
1)创建测试表
DELIMITER // create procedure pro_test1() begin declare i int; set i=1; while i<10000 do insert into test.test1(id,name) values(i, "aa"); set i=i+1; end while; end;//
##call pro_test1();
表大小:test1.ibd 368KB
2)delete后表大小: mysql> delete from test1; test1.ibd 384KB
3)回收表空间 mysql> alter table test1 engine=innodb; test1.ibd 96KB
mysql> select table_name, (data_length+index_length)/1024/1024 as total_mb, table_rows from information_schema.tables where table_schema='test' and table_name='TEST1';
+------------+------------+------------+
| table_name | total_mb | table_rows |
+------------+------------+------------+
| test1 | 0.01562500 | 0 |
+------------+------------+------------+
1 row in set (0.00 sec)
空间
独立
大小
数据
磁盘
不同
有效
一定量
位置
再次
动态
参数
同时
性能
文件
方式
物理
碎片
部分
存储
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
新华互联网科技学院
互联网科技垄断
互联网下的科技发展
互联网科技未来
互联网金融 科技
北京禾田雨橡互联网科技
互联网养老 桔豆科技
科技类的互联网平台
互联网巨头投资的硬核科技
互联网校园科技培训
互联网科技商业
杭州壁岐互联网科技有限公司
长沙茂晟互联网科技有限公司
国大互联网教育科技有限公司薪资
中国互联网有什么科技
互联网科技快讯热点
万物互联网智能科技
安徽九吞吴互联网科技有限公司
互联网企业和网络科技有限公司
六子台科技互联网展会
湖北九亚互联网络科技有限公司
没上市的科技互联网公司
融贸通互联网科技
掌上梦互联网科技
互联网高科技企业
丰台科技园 互联网公司
互联网科技股午盘股票涨跌
互联网和黑科技的看法
中国科技和美国互联网
武汉亿视互联网科技有限公司