Mysql的大字段问题

来源:互联网 发布:3m净水器淘宝 编辑:程序博客网 时间:2024/04/30 09:35

【问题描述】Mysql报错:

ERROR 1118 (42000) at line 703: Row size too large. The maximum row
size for the used table type, not counting BLOBs, is 8126. You have to
change some columns to TEXT or BLOBs

【导致问题的原因】
因为mysql-innodb是按照page存储数据的,每个page max size是16k,然后每个page两行数据,所以每行最大8k数据。如果你的字段是blob之类的话,会存储在page之外的溢出区里。
但是innodb默认的approach(羚羊)存储格式会把每个blob字段的前864个字节存储在page里,所以你的blob超过一定数量的话,单行大小就会超过8k,所以就报错了

【解决思路】
解决方式是使用innodb的Barracuda(梭鱼) 存储格式
这种格式对blob字段的处理方式是在page里头只存储一个20byte大小的指针,其它全存在溢出区,所以你轻易超不了8k

【详细步骤】
1. 打开mysql的配置my.ini。在innodb配置出添加:innodb_file_per_table=1
或者直接mysql命令行设置 :set GLOBAL innodb_file_per_table = 1
2. 然后命令检查下上述开关是否打开。

    show variables like '%per_table%';    +-----------------------+-------+    | Variable_name         | Value |    +-----------------------+-------+    | innodb_file_per_table | ON    |    +-----------------------+-------+
  1. 设置mysql全局变量:innodb_file_format = Barracuda(梭鱼)
    命令:
    set GLOBAL innodb_file_format = 'Barracuda';    show GLOBAL VARIABLES LIKE '%file_format%';    +--------------------------+-----------+    | Variable_name            | Value     |    +--------------------------+-----------+    | innodb_file_format       | Barracuda |    | innodb_file_format_check | ON        |    | innodb_file_format_max   | Barracuda |    +--------------------------+-----------+
  1. 设置对应表的行格式 属性:ROW_FORMAT=COMPRESSED
    然后检查下标的属性是否是你设置的:COMPRESSED
0 0
原创粉丝点击