溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mysql中怎么測試varchar類型最大長度

發(fā)布時間:2021-08-05 15:32:50 來源:億速云 閱讀:172 作者:Leah 欄目:MySQL數(shù)據(jù)庫

本篇文章為大家展示了mysql中怎么測試varchar類型最大長度,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

1.先看字符集為latin1時,每個字符應(yīng)該是占據(jù)一個byte
mysql> create table test(a varchar(65535)) engine=innodb charset=latin1;
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

mysql> create table test(a varchar(65533)) engine=innodb charset=latin1;
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

mysql> create table test(a varchar(65532)) engine=innodb charset=latin1;
Query OK, 0 rows affected (0.01 sec)

2.再看字符集為GBK時,每個字符應(yīng)該占據(jù)2個byte
mysql> drop table test;
Query OK, 0 rows affected (0.00 sec)

mysql> create table test(a varchar(32767)) engine=innodb charset=gbk;
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

mysql> create table test(a varchar(32766)) engine=innodb charset=gbk;
Query OK, 0 rows affected (0.00 sec)

3.當(dāng)字符集為UTF8時,每個字符占據(jù)了3個byte
mysql> drop table test;
Query OK, 0 rows affected (0.00 sec)

mysql> create table test(a varchar(65535)) engine=innodb charset=utf8;
ERROR 1074 (42000): Column length too big for column 'a' (max = 21845); use BLOB or TEXT instead

mysql> create table test(a varchar(21845)) engine=innodb 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

mysql> create table test(a varchar(21844)) engine=innodb charset=utf8;
Query OK, 0 rows affected (0.00 sec)


最后,如果表中所有varchar類型的列長度總和超過了65535,創(chuàng)建表時也會報錯
mysql> drop table test;
Query OK, 0 rows affected (0.00 sec)

mysql> create table test(a varchar(22000),b varchar(22000),c varchar(22000)) charset=latin1 engine=innodb;
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

上述內(nèi)容就是mysql中怎么測試varchar類型最大長度,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI