Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
root@localhost 03:54: [test]> create table t4(c int, c2 char(30), c3 varchar(21813)) charset=utf8;
ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
root@localhost 03:55: [test]> create table t4(c int, c2 char(30), c3 varchar(21812)) charset=utf8;
Query OK, 0 rows affected (0.04 sec)
字符类型若为gbk,每个字符最多占2个字节,最大长度不能超过32766;
字符类型若为utf8,每个字符最多占3个字节,最大长度不能超过21845。
则此处N的最大值为 (65535-1-2-4-30*3)/3=21812
减1的原因是实际行存储从第二个字节开始';
减2的原因是varchar头部的2个字节表示长度;
减4的原因是int类型的c占4个字节;
减30*3的原因是char(30)占用90个字节,编码是utf8。
mysql的vachar字段的类型虽然最大长度是65535,但是并不是能存这么多数据,最大可以到65533(不允许非空字段的时候),当允许非空字段的时候只能到65532。
转载于:https://blog.51cto.com/hexudong/1939795