mysql column legnth too big for_Column length too big for column 'Flist' (max = 21845);
建表語句報如下錯誤:
CREATE TABLE test_1 (
Fid bigint(20) unsigned NOT NULL,
Ftype tinyint(4) unsigned NOT NULL,
Flist varchar(65532) DEFAULT NULL,
Fstatus tinyint(3) unsigned DEFAULT '0',
Ftime bigint unsigned DEFAULT '0',
Faddtime bigint unsigned DEFAULT '0',
PRIMARY KEY (Fid,Ftype)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
建表報如下錯誤:
ERROR 1074 (42000): Column length too big for column 'Flist' (max = 21845); use BLOB or TEXT instead
原因分析
雖然知道m(xù)ysql建表的時候列長度有65535的限制,但是一直沒有時間整理這個問題,接著今天整理一下。
ERROR 1074 (42000): Column length too big for column 'Flist' (max = 21845); use BLOB or TEXT instead
從上面的報錯我們知道Flist列指定值不能大于21845 字節(jié)(mysql官方手冊中定義,創(chuàng)建表的字段長度限制為65535 bytes,這個是指所有列指定的長度和,當然不包括TEXT和BLOB類型的字段)。
還有一點我們需要注意的是我們定義列長度時指定的長度單位為字符,上面提到的65535限制的單位為字節(jié)。不同字符集下每個字符占用的字節(jié)數(shù)不同,utf8下每個字符占用3個字節(jié)(65535/3=21845),gbk下每個字符占用2個字節(jié)(65535/2=32767),latin1字符集下一個字符占用一個字節(jié)。
操作驗證
實驗1:
CREATE TABLE test_1 (
Flist varchar(21845) DEFAULT NULL
) ENGINE=InnoDB DEFAULT 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
##我們發(fā)現(xiàn)給表指定一個列,
列長度為21845字符(utf8下最大長度限制),但是建表依然報錯。這是因為還有別的一些開銷,
所以我們不能指定列長度為最大限制21845(測試發(fā)現(xiàn)指定長度為21844后建表成功)
實驗2:
CREATE TABLE test_1 (
Fid bigint(20) unsigned NOT NULL,
Ftype tinyint(4) unsigned NOT NULL,
Flist varchar(21844) DEFAULT NULL,
Fstatus tinyint(3) unsigned DEFAULT '0',
Ftime bigint unsigned DEFAULT '0',
Faddtime bigint unsigned DEFAULT '0',
PRIMARY KEY (Fid,Ftype)
) ENGINE=InnoDB DEFAULT 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
##雖然Flist 長度指定為21844,但是因為還
有其他非TEXT和BLOB字段存在,所以報錯。這是因為65535長度限制是針對表中所有列的長
度和的最大限制,如果列的長度和超過該值,建表依然會報錯。(除了TEXT和BLOB類型的字
段的)
總結
以上是生活随笔為你收集整理的mysql column legnth too big for_Column length too big for column 'Flist' (max = 21845);的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python extract的使用_Py
- 下一篇: action script3.0殿堂之路