zoukankan      html  css  js  c++  java
  • MySql 存储大量长字节 Text报错处理办法

    今天线上版本的错误:
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline.

    【导致问题的原因】
    总结了下原因是因为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每张表都是独立存储空间的开关。
     
    2. 然后命令检查下上述开关是否打开。
    show variables like '%per_table%';
     
    Mysql的大字段问题
    如上图开关就打开了。
     
    3. 设置mysql全局变量:innodb_file_format = Barracuda(梭鱼)
    命令:set GLOBAL innodb_file_format = 'Barracuda';
    然后检查下是否设置好了:
    命令:show GLOBAL VARIABLES LIKE '%file_format%';

    如上就是好了
     
    4. 设置对应表的属性:ROW_FORMAT=COMPRESSED
    然后检查下标的属性是否是你设置的:COMPRESSED
     
    5. 如上步骤以后,就OK了
     
    【补充】
    1. 最后一定要检查下相关表的属性,一定要是COMPRESSED,如下图
    Mysql的大字段问题

    这点一定要注意,这是导致线上事故的一个重要原因

  • 相关阅读:
    mac os programming
    Rejecting Good Engineers?
    Do Undergrads in MIT Struggle to Obtain Good Grades?
    Go to industry?
    LaTex Tricks
    Convert jupyter notebooks to python files
    How to get gradients with respect to the inputs in pytorch
    Uninstall cuda 9.1 and install cuda 8.0
    How to edit codes on the server which runs jupyter notebook using your pc's bwroser
    Leetcode No.94 Binary Tree Inorder Traversal二叉树中序遍历(c++实现)
  • 原文地址:https://www.cnblogs.com/leolzi/p/10643864.html
Copyright © 2011-2022 走看看