原文地址:http://www.cnblogs.com/billyxp/p/3342969.html

对于越来越多的数据,数据库的容量越来越大,压缩也就越来越常见了。在我的实际工作中进行过多次压缩工作,也遇到多次问题,在此和大家分享一下。

首先,我们先说说怎么使用innodb的压缩.

第一,mysql的版本需要大于5.5第二,设置innodb_file_format=barracuda
第三,create table或者alter talble 增加 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;(默认的key_block_size=16)

其实很简单,根据经验,一般压缩比例可以达到30%-40%

然后,我们说说我在压缩过程中遇到的坑和发现的关联,当然有些比较二。

No1:

问题:使用脚本批量alter操作,只动态修改了实例的innodb_file_format=barracuda,然后alter所有数据库中的表。并没有修改配置文件中的设置。

结果:表中已有数据被压缩,但是在重启之后,由于innodb_file_format参数被重新修改成antelope,导致后续写入的数据没有被压缩(虽然表结构中有row_format=compressed,但是不会起作用),最终表体积仍然很大。

教训:实例和配置文件要同步修改。(这个错误最二,太低级 T_T,不解释了。)

No2:

问题:在innodb_file_format=antelope的情况下,建立压缩表(表结构中带有row_format=compressed),然后在设置innodb_file_format=barracuda。

结果:表结构中的row_format=compressed被忽略,后续写入表的数据并没有被压缩,最终导致表体积大。

教训:先修改innodb_file_format(session和global都需要修改),在create table或者alter table。

但是以上这点有个坑人的地方,在错误的顺序下,表是可以被成功建立了,只是会有warning,但是表结构中会有row_format=compressed,在后期排查的时候非常误导人!

+--------------------------+----------+| Variable_name            | Value    |+--------------------------+----------+| innodb_file_format       | Antelope || innodb_file_format_check | ON       || innodb_file_format_max   | Antelope |+--------------------------+----------+3 rows in set (0.00 sec)

test> create table test_1 (x int) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; 
Query OK, 0 rows affected, 4 warnings (0.07 sec)

test> show warnings; 
+---------+------+-----------------------------------------------------------------------+ 
| Level | Code | Message | 
+---------+------+-----------------------------------------------------------------------+ 
| Warning | 1478 | InnoDB: KEY_BLOCK_SIZE requires innodb_file_format > Antelope . | 
| Warning | 1478 | InnoDB: ignoring KEY_BLOCK_SIZE=8 . | 
| Warning | 1478 | InnoDB: ROW_FORMAT=COMPRESSED requires innodb_file_format > Antelope . | 
| Warning | 1478 | InnoDB: assuming ROW_FORMAT=COMPACT . | 
+---------+------+-----------------------------------------------------------------------+ 
4 rows in set (0.00 sec)

我们可以从warnings中看见,压缩设置被忽略了。但是最坑爹的一点是,如果我们show create table会有如下结果:

test_1 | CREATE TABLE `test_1` (  `x` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8

在这种情况下,我们吸取教训,不能使用show create table看压缩状态,而是应该用show table status;

show table status like 'test_1'\G;*************************** 1. row ***************************Name: test_1Engine: InnoDBVersion: 10Row_format: CompactRows: 0Avg_row_length: 0Data_length: 16384Max_data_length: 0Index_length: 0Data_free: 0Auto_increment: NULLCreate_time: 2013-09-27 15:59:13Update_time: NULLCheck_time: NULLCollation: utf8_general_ciChecksum: NULLCreate_options: row_format=COMPRESSED KEY_BLOCK_SIZE=8Comment:1 row in set (0.00 sec)

坑爹啊,不说了。正常应该这个样子

show table status like 'test_2'\G;*************************** 1. row ***************************Name: test_2Engine: InnoDBVersion: 10Row_format: CompressedRows: 0Avg_row_length: 0Data_length: 8192Max_data_length: 0Index_length: 0Data_free: 0Auto_increment: NULLCreate_time: 2013-09-27 16:09:51Update_time: NULLCheck_time: NULLCollation: utf8_general_ciChecksum: NULLCreate_options: row_format=COMPRESSED KEY_BLOCK_SIZE=8Comment:1 row in set (0.00 sec)

No3:

发现和innodb_file_format相关的2个参数:

+--------------------------+-----------+| Variable_name            | Value     |+--------------------------+-----------+| innodb_file_format       | Barracuda || innodb_file_format_check | ON        || innodb_file_format_max   | Barracuda |+--------------------------+-----------+3 rows in set (0.00 sec)

官方的解释可以参考如下的链接:http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_file_format

测试过程中发现,如果是innodb_file_format=barracuda而innodb_file_format_max=antelop,那么在建立压缩表的时候,max会自动变成barracuda。

localhost.test>show global variables like 'innodb_file_format%';+--------------------------+-----------+| Variable_name            | Value     |+--------------------------+-----------+| innodb_file_format       | Barracuda || innodb_file_format_check | ON        || innodb_file_format_max   | Antelope  |+--------------------------+-----------+3 rows in set (0.00 sec)localhost.test>create table test_4(x int) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;Query OK, 0 rows affected (0.01 sec)localhost.test>show global variables like 'innodb_file_format%';+--------------------------+-----------+| Variable_name            | Value     |+--------------------------+-----------+| innodb_file_format       | Barracuda || innodb_file_format_check | ON        || innodb_file_format_max   | Barracuda |+--------------------------+-----------+3 rows in set (0.00 sec)

如果innodb_file_format_check这参数解释的,决定innodb是否会检查共享表空间中的表格式的tag,如果检查开启,那么当标记的表格式的tag高于innodb可以支撑的表格式,那么innodb会报错,并停止启动。如果支持,那么会将innodb_file_format_max的值改为这个tag的值。

以下是参考材料

  • innodb_file_format

  • Command-Line Format

  • --innodb_file_format=#

  • Option-File Format

  • innodb_file_format

  • System Variable Name

  • innodb_file_format

  • Variable Scope

  • Global

  • Dynamic Variable

  • Yes

  • Permitted Values (<= 5.5.6)

  • Type

  • string

  • Default

  • Barracuda

  • Valid Values

  • Antelope

  • Barracuda

  • Permitted Values (>= 5.5.7)

  • Type

  • string

  • Default

  • Antelope

  • Valid Values

  • Antelope

  • Barracuda

  • The file format to use for new InnoDB tables. Currently, Antelope andBarracuda are supported. This applies only for tables that have their own tablespace, so for it to have an effect, innodb_file_per_table must be enabled. The Barracuda file format is required for certain InnoDB features such as table compression.

  • innodb_file_format_check

  • Command-Line Format

  • --innodb_file_format_check=#

  • Option-File Format

  • innodb_file_format_check

  • System Variable Name

  • innodb_file_format_check

  • Variable Scope

  • Global

  • Dynamic Variable

  • No

  • Permitted Values

  • Type

  • string

  • Default

  • Antelope

  • Permitted Values (>= 5.5.1)

  • Type

  • string

  • Default

  • Barracuda

  • Permitted Values (>= 5.5.5)

  • Type

  • boolean

  • Default

  • ON

  • As of MySQL 5.5.5, this variable can be set to 1 or 0 at server startup to enable or disable whether InnoDB checks the file format tag in the shared tablespace (for example, Antelope or Barracuda ). If the tag is checked and is higher than that supported by the current version of InnoDB , an error occurs and InnoDBdoes not start. If the tag is not higher, InnoDB sets the value ofinnodb_file_format_max to the file format tag. 
    Before MySQL 5.5.5, this variable can be set to 1 or 0 at server startup to enable or disable whether InnoDB checks the file format tag in the shared tablespace. If the tag is checked and is higher than that supported by the current version ofInnoDB , an error occurs and InnoDB does not start. If the tag is not higher,InnoDB sets the value of innodb_file_format_check to the file format tag, which is the value seen at runtime. 
    Note 
    Despite the default value sometimes being displayed as ON or OFF , always use the numeric values 1 or 0 to turn this option on or off in your configuration file or command line.

  • innodb_file_format_max

  • Introduced

  • 5.5.5

  • Command-Line Format

  • --innodb_file_format_max=#

  • Option-File Format

  • innodb_file_format_max

  • System Variable Name

  • innodb_file_format_max

  • Variable Scope

  • Global

  • Dynamic Variable

  • Yes

  • Permitted Values

  • Type

  • string

  • Default

  • Antelope

  • Valid Values

  • Antelope

  • Barracuda

  • At server startup, InnoDB sets the value of innodb_file_format_max to the file format tag in the shared tablespace (for example, Antelope or Barracuda ). If the server creates or opens a table with a “higher” file format, it sets the value ofinnodb_file_format_max to that format. 
    This variable was added in MySQL 5.5.5.

转载于:https://blog.51cto.com/80888888/1566639

Innodb表压缩过程中遇到的坑(innodb_file_format) - billy鹏相关推荐

  1. mysql5.7.16 表空间加密,MySQL :: MySQL 5.7参考手册:: A.16 MySQL 5.7 FAQ:InnoDB表空间加密...

    A.16.1. 数据是否被授权查看的用户解密? 是.InnoDB表空间加密旨在为客户提供在数据库中透明地应用加密而不影响现有应用程序的能力.以加密格式返回数据会破坏大多数现有的应用程序.InnoDB表 ...

  2. mysql表分区占用存储_MySQL 分区分表应用场景分析和分区中可能遇到的坑点

    MySQL的分区和分表应用场景分析 在日常工作中当我们的某张表的数据量过大的时候,首当其冲的可能就是进行分区和分表,但是是如何分区或者分表都要结合一点的业务场景下进行分析,才会显著的提升性能,来聊一聊 ...

  3. mysql 分区表_MySQL 分区分表应用场景分析和分区中可能遇到的坑点

    MySQL的分区和分表应用场景分析 在日常工作中当我们的某张表的数据量过大的时候,首当其冲的可能就是进行分区和分表,但是是如何分区或者分表都要结合一点的业务场景下进行分析,才会显著的提升性能,来聊一聊 ...

  4. MySQL的InnoDB存储引擎中,缓冲池中的Changer Buffer与系统表空间中的Changer Buffer的关系

    MySQL的InnoDB存储引擎中,缓冲池中和系统表空间中都存在Changer Buffer,那它们之间的关系是怎样的呢?先来一张InnoDB存储引擎的架构图: 翻阅了MySQL官网发现如下: 1.h ...

  5. mysql 压缩表_MySQL InnoDB 表压缩(行格式压缩)

    MySQL InnoDB支持数据压缩,有两种数据压缩方式,第一种为表压缩,通常也称之为行格式压缩,另外一种是页压缩,页压缩对操作系统及文件系统有一定的要求.本文主要介绍表压缩(行格式压缩)的原理及使用 ...

  6. MYSQL 5.7 INNODB 表空间

    背景介绍 由于InnoDB 引擎支持ACID.良好的读写性能,还有许多其他对数据库服务具有重要意义的特性,InnoDB已经成为MySQL最受欢迎的存储引擎. 在本文中,我们将介绍InnoDB表空间和它 ...

  7. mysql innodb 表数据压缩

    记得一次面试中,面试官问我是否知道表的压缩,这个时候我才知道mysql有个表压缩这么个功能,今天试用下看看表的压缩率怎么样. 这里分两个部分说明,第一部分:官方文档说明:第二部分:具体实例测试. [第 ...

  8. mysql多大_mysql的innodb表到底占用多大的空间?

    问题背景:最近某个数据库服务器磁盘告警,在数据库内查询information_schema.tables查看数据库一共占用了8个T左右的空间,但是在服务器上通过du命令查看数据库文件夹占用了18个T( ...

  9. innodb表 手工导入导出

    上一篇文章介绍了"innobackupex 热备指定库表操作",分析其整个过程,就是将表的字典和数据文件导出在导入的原理,那么针对单表的备份与恢复(新实例或者新库中恢复),我们可以 ...

最新文章

  1. 学习ui设计的流程是什么
  2. Linux jdk配置
  3. Node.js实现Excel转JSON
  4. 百度之星2019 初赛一 题解
  5. 读《高性能网站建设指南》有感
  6. OpenCV访问像素的三种方法
  7. 前端结构解析系列之二:凯旋门结构
  8. 浅谈URL生成方式的演变
  9. 【图像融合】基于matlab curvelet变换图像融合【含Matlab源码 776期】
  10. Java练手项目-王者荣耀项目源码分享!
  11. Apollo CANbus 模块原理及源码学习
  12. 拓扑排序算法 C语言实现
  13. WPS2005 For Linux 序列号
  14. Office 365网络链接概览(三)--专线express route
  15. 数据加密 ---- SHA 加密
  16. Android接入三方登录——QQ、微信、Facebook、Twitter
  17. C++报错:[Warning] statement has no effect [-Wunused-value]
  18. 响应式布局之媒体查询
  19. 嵌入式软件解决ADC电量显示问题经验分享
  20. 『暴走漫画』-快活啊~尽情释放男人的天性啊~

热门文章

  1. 系统开出出现问题~~~\WINDOWS\SYSTEM32\CONFIG\SYSTEM 损坏或丢失无法开机
  2. 在TMG2010中发布Web服务器场
  3. 新版蚂蚁网有抄袭怪兽吗?
  4. ??ArcGIS server公交线路动态分段问题
  5. 【工具使用系列】关于 MATLAB 机器视觉,你需要知道的事
  6. Linux学习总结(7)——阿里云centeros服务器上安装 jdk,tomcat,mysql
  7. Android版网易云音乐唱片机唱片磁盘旋转及唱片机机械臂动画关键代码实现思路...
  8. Java控制语句——for循环
  9. 转帖-Linux 磁盘坏道检测和修复
  10. linux 网络编程之信号机制