MySQL表空间集
--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表空间集的更多相关文章
- mysql 表空间
开启了Innodb的innodb_file_per_table这个参数之后[innodb_file_per_table = 1],也就是启用InnoDB的独立表空间模式,便于管理.此时,在新建的inn ...
- MySQL 表空间传输
聊到MySQL数据迁移的话题,表空间传输时一个很实用的方法. 在MySQL 5.6 Oracle引入了一个可移动表空间的特征(复制的表空间到另一个服务器)和Percona Server采用部分备份,这 ...
- 详解MySQL表空间以及ibdata1文件过大问题
ibdata1文件过大 原因分析 ibdata1是一个用来构建innodb系统表空间的文件,关于系统表空间详细介绍参考MySQL官网文档 上面是一个数据库的ibdata1文件,达到了780多G,而且还 ...
- mysql表空间加密 keyring encryption
从5.7.11开始,mysql开始支持物理表空间的加密,它使用两层加密架构.包括:master key 和 tablespace key master key用于加密tablespace key,加密 ...
- innodb和myisam数据库文件存储详解以及mysql表空间
数据库常用的两种引擎有Innodb和Myisam,关于二者的区别参考:https://www.cnblogs.com/qlqwjy/p/7965460.html 1.关于数据库的存储在两种引擎的存储是 ...
- mysql表空间传输(ERROR 1808) row_format设置
文章结构如下: 从MYSQL5.6版本开始,引入了传输表空间这个功能,可以把一张表从一个数据库移到另一个数据库或者机器上.迁移的时候很方便,尤其是大表. 由于本次达到测试使用版本5.6.38传到5.7 ...
- Mysql 表空间和 数据页空洞
一.表空间1.表空间: innodb 引擎存储的最高层: 存放所有的数据2.独立表空间:Mysql 版本 5.6 后默认开启的单表单空间(1)Innodb 默认存储引擎页的大小为 16K :默认表空间 ...
- MySQL表空间回收的正确姿势
不知道大家有没有遇到这样的一种情况,线上业务在MySQL表上做增删改查操作,随着时间的推移,表里面的数据越来越多,表数据文件越来越大,数据库占用的空间自然也逐渐增长 为了缩小磁盘上表数据文件占用的空间 ...
- mysql 表空间及索引的查看方法
CONCAT : concat() 方法用于连接两个或多个数组. database : 数据库(11张) 数据库,简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件 ...
随机推荐
- 第一个SpringMVC实例和解析(HelloSpringMVC)
1. 开发步骤: (1)增加Spring支持 下载Spring安装包和其依赖的commons-logging.jar,复制到项目Web应用的lib文件夹(WebRoot/WEB-INF/lib): S ...
- DOM元素拖拽效果
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 使用ant自动构建apk
最近因渠道过多,需要单独接入渠道支付sdk的渠道也很多,而首发在即.人手不足,所以着手了部分相关的工作,看了下目前的操作流程..无奈人比较懒,所以决定进行一波简化的技术,先考虑到了两种方案: 1)脚本 ...
- JS - dateFormat
// date必填, pattern默认'yyyy-MM-dd HH:mm:ss'function dateFormat (date, pattern) { var week = {'0':'日', ...
- localStorage和sessionStorage的使用方法和一些特性介绍
本文主要介绍的是localStorage和sessionStorage的使用方法和一些特性,以及一些其他的存储方式的比较. 客服端存储方案包括以下几种: 1.Cookie 2.Us ...
- docker~Dockerfile方式生成控制台和Api项目的镜像
回到目录 一些理论知识 将控制台程序和API程序部署到docker,然后运行它,这个首先要解决的问题就是如何在linux平台运行C#代码,哈哈,很古老的问题,事实上,对于这种问题早在几年前就已经有了解 ...
- 51nod_1298:圆与三角形(计算几何)
题目链接 判断圆和三角形是否相交 可以转化为 判断三条线段是否和圆相交 #include<iostream> #include<cstdio> #include< ...
- HTML5 开发APP(打开相册以及图片上传)
我们开发app,常常会遇到让用户上传文件的功能.比如让用户上传头像.我公司的业务要求是让用户上传支付宝收款二维码,来实现用户提现的功能.想要调用相册要靠HTML Plus来实现.先上效果图 基本功能是 ...
- MySQL优化 - 性能分析与查询优化
优化应贯穿整个产品开发周期中,比如编写复杂SQL时查看执行计划,安装MySQL服务器时尽量合理配置(见过太多完全使用默认配置安装的情况),根据应用负载选择合理的硬件配置等. 1.性能分析 性能分析包含 ...
- Java GC - 垃圾回收机制
1.简介 对于Java developer来说,了解JVM GC工作原理能够帮助我们开发出更优秀的应用,同时在处理JVM瓶颈时能够更加自由.在最近一年的应用开发中能体会到这些知识带来的好处,并且让我们 ...