Mysql的大字段問題

【問題描述】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
發佈了30 篇原創文章 · 獲贊 4 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章