1. 程式人生 > >Mysql_大字段問題Row size too large.....not counting BLOBs, is 8126.

Mysql_大字段問題Row size too large.....not counting BLOBs, is 8126.

var log 都是 variable bytes alter 設置 分享圖片 value

【問題描述】

1.從myslq(5.7.19-0ubuntu0.16.04.1)中導出sql腳本,導入到mysql(5.5.27)中,報如下錯誤: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
2.程序向mysql(5.5.27)中存入數據報錯如下: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%‘ 技術分享圖片 如圖就是打開的了。如果value值顯示OFF,只需重啟mysql服務即可。 3.設置mysql全局變量:innodb_file_format = Barracuda(梭魚) 命令:set GLOBAL innodb_file_format = ‘Barracuda‘; 然後檢查下是否設置好了: 命令:show GLOBAL VARIABLES LIKE ‘%file_format%‘; 技術分享圖片
4.設置對應表的屬性:ROW_FORMAT=DYNAMIC ALTER TABLE zgzw_jibing_table ROW_FORMAT=DYNAMIC 技術分享圖片 按照如上步驟操作就OK了。

【聲明】

本文參考了:http://blog.sina.com.cn/s/blog_8e9cceee0101k65j.html

Mysql_大字段問題Row size too large.....not counting BLOBs, is 8126.