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张) 数据库,简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件 ...
随机推荐
- C# 文字转换最简单的方法
引用Microsoft.VisualBasic string text=Strings.StrConv("需要转换的文字", VbStrConv.TraditionalChines ...
- 严重: Could not synchronize database state with session org.hibernate.exception.DataException: Could not execute JDBC batch update
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #ff2600 } p.p2 { margin: 0.0px 0 ...
- jquery.validata.js 插件2
结合上面的,今天写一下validate的使用方法. validate()验证所选的form. validate 方法返回一个 Validator 对象.Validator 对象有很多方法可以用来引发校 ...
- Redis配置文件redis.conf参数配置详解
########################################## 常规 ########################################## daemonize n ...
- NLP中的用N-gram语言模型做英语完型填空的环境搭建
本文是对xing_NLP中的用N-gram语言模型做完型填空这样一个NLP项目环境搭建的一个说明,本来想写在README.md中.第一次用github中的wiki,想想尝试一下也不错,然而格式非常的混 ...
- tensorflow max_pool(最大池化)应用
1.最大池化 max pooling是CNN当中的最大值池化操作,其实用法和卷积很类似. tf.nn.max_pool(value, ksize, strides, padding, name=Non ...
- (转)xml
1 XML理论回顾 1.1 XML概述 1.XML是可扩展标记语言.是由W3C指定并维护的,目前最新的版本是1.0 2.XML作用: 2.1传输数据,它是一种通用的数据交换格式 2.2配置文件. 1 ...
- (转)maven镜像路径配置
很多maven包无法自动下载怎么办?设置maven镜像setting.xml <mirror> <id>repo2</id> <mirrorOf>cen ...
- swift 3.0 基础练习 面向对象 类的扩展
要求 为NSString类添加split功能 为NSString类添加一个函数func split(splitStr: NSString)-> [NSString],split是把字符串以特定的 ...
- ubuntu上安装nginx+mysql+php5-fpm(PHP5 - FastCGI Process Manager)
题外话:由于近段时间测试环境ssh链路质量不大好,经常短线.故我把整个安装过程放到screen里去执行,以防止断线中断了安装过程.执行screen -S install,这样断线后,只要再执行scre ...