--MySQL表空间集
----------------------2014-09-20

1. 收缩ibdata的方法,目前MySQL依然没有提供收缩ibdata的方法,只能重构,下面是5.7的步骤。

Decreasing the Size of the InnoDB Tablespace
Currently, you cannot remove a data file from the system tablespace. To decrease the system tablespace size, use this procedure: 1. Use mysqldump to dump all your InnoDB tables, including InnoDB tables located in the MySQL database. As of 5.6, there are five InnoDB tables included in the MySQL database: mysql> select table_name from information_schema.tables where table_schema='mysql' and engine='InnoDB';
+----------------------+
| table_name |
+----------------------+
| innodb_index_stats |
| innodb_table_stats |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
+----------------------+
5 rows in set (0.00 sec) Stop the server. 2. Remove all the existing tablespace files (*.ibd), including the ibdata and ib_log files. Do not forget to remove *.ibd files for tables located in the MySQL database. 3. Remove any .frm files for InnoDB tables. 4. Configure a new tablespace. 5. Restart the server. 6. Import the dump files.

2. 再看一个官方说明,file-per-table的优势,同时也指出了ibdata文件的空间只能被重用,但无法释放给操作系统。

You can reclaim operating system disk space when truncating or dropping a table. For tables created when file-per-table mode is turned off, truncating or dropping the tables creates free space internally in the ibdata files but the free space can only be used for new InnoDB data.

3. 对于file-per-table的表,回收空间,使用optimize table,实现原理如下面所示,其实就是重建+改名。

You can run OPTIMIZE TABLE to compact or recreate a tablespace. When you run an OPTIMIZE TABLE, InnoDB will create a new .ibd file with a temporary name, using only the space required to store actual data. When the optimization is complete, InnoDB removes the old .ibd file and replaces it with the new .ibd file. If the previous .ibd file had grown significantly but actual data only accounted for a portion of its size, running OPTIMIZE TABLE allows you to reclaim the unused space.

4. innodb的索引相关,5.5版mysql中测试索引的添加过程,看看mysql做了哪些事情。

CREATE TABLE `tindex` (
`id` int(11) DEFAULT NULL,
`name` char(10) DEFAULT NULL,
`address` varchar(20) NOT NULL,
`c3` char(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;  --创建一个innodb的表 mysql> alter table tindex add index idx_name(name);       --添加索引的name列
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show profile for query 3;                  --查看profile
+------------------------------+----------+
| Status | Duration |
+------------------------------+----------+
| starting | 0.000087 |
| checking permissions | 0.000004 |
| checking permissions | 0.000004 |
| init | 0.000007 |
| Opening tables | 0.000022 |
| System lock | 0.000008 |
| setup | 0.000025 |
| creating table | 0.013806 |            --创建临时表
| After create | 0.000003 |
| manage keys | 0.019027 |
| rename result table | 0.000236 |            --完成索引创建工作和表同步后,rename结果表
| end | 0.000017 |
| Waiting for query cache lock | 0.000002 |
| end | 0.000004 |
| query end | 0.000003 |
| closing tables | 0.000006 |
| freeing items | 0.000013 |
| cleaning up | 0.000002 |
+------------------------------+----------+
18 rows in set (0.00 sec)

--可见就是重建了表,同样alter table tindex engine innodb; 也就是会重建一下表(虽然表本来就是innodb的)

-- 还有optimize操作,实质就是doing recreate + analyze。

For InnoDB tables prior to 5.7.4 and other table types, MySQL locks the table during the time OPTIMIZE TABLE is running. As of MySQL 5.7.4, OPTIMIZE TABLE is performed online for regular and partitioned InnoDB tables.

总之:5.6之前没有online DDL,所以只要涉及到结构的改变都是重建!

有了online ddl后一些操作不再需要重建表,参考http://dev.mysql.com/doc/refman/5.7/en/innodb-create-index-overview.html#innodb-online-ddl-summary-grid

MySQL表空间集的更多相关文章

  1. mysql 表空间

    开启了Innodb的innodb_file_per_table这个参数之后[innodb_file_per_table = 1],也就是启用InnoDB的独立表空间模式,便于管理.此时,在新建的inn ...

  2. MySQL 表空间传输

    聊到MySQL数据迁移的话题,表空间传输时一个很实用的方法. 在MySQL 5.6 Oracle引入了一个可移动表空间的特征(复制的表空间到另一个服务器)和Percona Server采用部分备份,这 ...

  3. 详解MySQL表空间以及ibdata1文件过大问题

    ibdata1文件过大 原因分析 ibdata1是一个用来构建innodb系统表空间的文件,关于系统表空间详细介绍参考MySQL官网文档 上面是一个数据库的ibdata1文件,达到了780多G,而且还 ...

  4. mysql表空间加密 keyring encryption

    从5.7.11开始,mysql开始支持物理表空间的加密,它使用两层加密架构.包括:master key 和 tablespace key master key用于加密tablespace key,加密 ...

  5. innodb和myisam数据库文件存储详解以及mysql表空间

    数据库常用的两种引擎有Innodb和Myisam,关于二者的区别参考:https://www.cnblogs.com/qlqwjy/p/7965460.html 1.关于数据库的存储在两种引擎的存储是 ...

  6. mysql表空间传输(ERROR 1808) row_format设置

    文章结构如下: 从MYSQL5.6版本开始,引入了传输表空间这个功能,可以把一张表从一个数据库移到另一个数据库或者机器上.迁移的时候很方便,尤其是大表. 由于本次达到测试使用版本5.6.38传到5.7 ...

  7. Mysql 表空间和 数据页空洞

    一.表空间1.表空间: innodb 引擎存储的最高层: 存放所有的数据2.独立表空间:Mysql 版本 5.6 后默认开启的单表单空间(1)Innodb 默认存储引擎页的大小为 16K :默认表空间 ...

  8. MySQL表空间回收的正确姿势

    不知道大家有没有遇到这样的一种情况,线上业务在MySQL表上做增删改查操作,随着时间的推移,表里面的数据越来越多,表数据文件越来越大,数据库占用的空间自然也逐渐增长 为了缩小磁盘上表数据文件占用的空间 ...

  9. mysql 表空间及索引的查看方法

        CONCAT : concat() 方法用于连接两个或多个数组.    database : 数据库(11张) 数据库,简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件 ...

随机推荐

  1. 百万级数据mysql分区

    1. 什么是表分区? 表分区,是指根据一定规则,将数据库中的一张表分解成多个更小的,容易管理的部分.从逻辑上看,只有一张表,但是底层却是由多个物理分区组成. 2. 表分区与分表的区别 分表:指的是通过 ...

  2. RabbitMQ插件安装

    RabbitMQ的有些插件没有集成在初始的安装中,它们需要额外安装,这些文件的后缀为.ez,安装时需要将.ez文件拷贝到安装的插件目录.以下是不同系统中默认安装的插件目录路径: 插件目录 Linux ...

  3. 入门Android开发

    一个工作1年多一点的前端狗,由于公司需要,开始接触Android,也是第一次写博客,以后学到的技术每天都会写篇博客,让我们一起进步. Android 系统开发应用程序,为我们提供了哪些东西. 一.四大 ...

  4. (转载)开源ckplayer 网页播放器, 跨平台(html5, mobile),flv, f4v, mp4, rtmp协议. webm, ogg, m3u8 !

    文章链接:http://justcoding.iteye.com/blog/2110275 CKplayer,其全称为超酷flv播放器,它是一款用于网页上播放视频的软件,支持的格式有:http协议上的 ...

  5. ansible的安装

    安装 ansible-server的安装 client需要有python2.5以上 的python server和client都关闭了selinux server端: 网址: http://www.a ...

  6. POJ 3984 路径输出

    迷宫问题 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, ...

  7. 猜年龄---while循环

    #!/usr/bin/env python# -*- coding:utf-8 -*-# Author:Andy Chen age_of_oldboy = 56 count = 0while True ...

  8. es6的新内容

    前端学习总结(十八)ES6--新一代的javascript 发表于2016/6/11 21:44:27  2733人阅读 分类: javascript 简介 ECMAScript 6(以下简称ES6) ...

  9. C# 设计模式之空对象模式

    最近看了不少的书籍和视频等相关资料,决定自己边学习边写一下个人对设计模式的理解,如果有不对的请大家多多指正. 今天先说说我个人觉得最简单的设计模式 -- [空对象模式] 空对象模式可以减少客户端对对象 ...

  10. Weak 和 Strong

    介绍: ARC是自iOS 5之后增加的新特性,完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autorelease语句.你不再需要担心内存管理,因为编译 ...