root@localhost : test 10:30:54>CREATE TABLE tb_test (
-> recordid varchar(32) NOT NULL,
-> areaShow varchar(10000) DEFAULT NULL,
-> areaShow1 varchar(10000) DEFAULT NULL,
-> areaShow2 varchar(10000) DEFAULT NULL,
-> PRIMARY KEY (recordid)
-> ) 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. You have to change some columns to TEXT or BLOBs
報(bào)錯(cuò)
root@localhost : test 10:31:01>CREATE TABLE tb_test (
-> recordid varchar(32) NOT NULL,
-> areaShow varchar(30000) DEFAULT NULL,
-> areaShow1 varchar(30000) DEFAULT NULL,
-> areaShow2 varchar(30000) DEFAULT NULL,
-> PRIMARY KEY (recordid)
-> ) ENGINE=INNODB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected, 3 warnings (0.26 sec)
可以建立,只是類型被轉(zhuǎn)換了。
root@localhost : test 10:31:14>show warnings;
+-------+------+----------------------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------------------+
| Note | 1246 | Converting column 'areaShow' from VARCHAR to TEXT |
| Note | 1246 | Converting column 'areaShow1' from VARCHAR to TEXT |
| Note | 1246 | Converting column 'areaShow2' from VARCHAR to TEXT |
+-------+------+----------------------------------------------------+
3 rows in set (0.00 sec)
疑問:
為什么字段小(10000)的反而報(bào)錯(cuò),而大(30000)的則可以建立。為什么小的不能直接轉(zhuǎn)換呢?
解決:
這里多感謝orczhou的幫助,原來(lái)MySQL在建表的時(shí)候有個(gè)限制:MySQL要求一個(gè)行的定義長(zhǎng)度不能超過(guò)65535。具體的原因可以看:
http://dev.mysql.com/doc/refman/5.1/en/silent-column-changes.html
(1)單個(gè)字段如果大于65535,則轉(zhuǎn)換為TEXT 。
(2)單行最大限制為65535,這里不包括TEXT、BLOB。
按照上面總結(jié)的限制,來(lái)解釋出現(xiàn)的現(xiàn)象:
第一個(gè)情況是:
單個(gè)字段長(zhǎng)度:varchar(10000) ,字節(jié)數(shù):10000*3(utf8)+(1 or 2) = 30000 ,小于65535,可以建立。
單行記錄長(zhǎng)度:varchar(10000)*3,字節(jié)數(shù):30000*3(utf8)+(1 or 2) = 90000,大于65535,不能建立,所以報(bào)錯(cuò):
ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs
第二個(gè)情況是:
單個(gè)字段長(zhǎng)度:varchar(30000) ,字節(jié)數(shù):30000*3+(1 or 2) = 90000 , 大于65535,需要轉(zhuǎn)換成TEXT,才可以建立。所以報(bào)warnings。
單行記錄長(zhǎng)度:varchar(30000)*3,因?yàn)槊總(gè)字段都被轉(zhuǎn)換成了TEXT,而TEXT沒有限制,所以可以建立表。
root@localhost : test 10:31:14>show warnings;
+-------+------+----------------------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------------------+
| Note | 1246 | Converting column 'areaShow' from VARCHAR to TEXT |
| Note | 1246 | Converting column 'areaShow1' from VARCHAR to TEXT |
| Note | 1246 | Converting column 'areaShow2' from VARCHAR to TEXT |
+-------+------+----------------------------------------------------+
還可以看看
其他文章,謝謝您的閱讀。
網(wǎng)站申明:系本文編輯轉(zhuǎn)載,來(lái)源于網(wǎng)絡(luò),目的在于傳遞更多信息,并不代表本網(wǎng)贊同其觀點(diǎn)和對(duì)其真實(shí)性負(fù)責(zé),所有權(quán)歸屬原作者。如內(nèi)容、圖片有任何版權(quán)問題,請(qǐng)
聯(lián)系我們刪除。