当前位置:网站首页>What is the maximum length of MySQL varchar field

What is the maximum length of MySQL varchar field

2022-07-06 12:23:00 wx5caecf2ed0645


varchar(n),n What does it mean ?

MySQL5.0.3 Before varchar(n) there n Represents the number of bytes

MySQL5.0.3 after varchar(n) there n Indicates the number of characters , such as varchar(200), It can be stored in both English and Chinese 200 individual

n What is the maximum

MySQL Line length

MySQL It is required that the length of a line definition cannot exceed 65535 Bytes , barring text、blob And so on ,varchar The length is limited by this length , And other non large fields cannot add up to more than 65535 Bytes .

If the above limit is exceeded, an error will be reported :

drop table if EXISTS test1111;

create table test1111(

 id char(255) null,

content varchar(21830) null

)ENGINE=InnoDB DEFAULT CHARSET=utf8;

[Err] 1118 - 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

 varchar(n) Take a few bytes

varchar(n) Taking a few bytes has something to do with the character set :

If the character type is gbk, Each character occupies 2 Bytes

If the character type is utf8, Each character takes up a maximum of 3 Bytes

varchar What's the maximum length

According to character set , If the character type is gbk, Each character occupies 2 Bytes , The maximum length cannot exceed 32766, If the character type is utf8, Each character takes up a maximum of 3 Bytes , The maximum length cannot exceed 21845, If the limit is exceeded , Will automatically varchar Type to mediumtext or longtext, for example :

drop table if EXISTS test1111;

create table test1111(

 id char(255) null,

content varchar(63000) null

);

desc test1111;


result :

CREATE TABLE `test1111` (

  `id` char(255) DEFAULT NULL,

  `content` mediumtext

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


原网站

版权声明
本文为[wx5caecf2ed0645]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131540130240.html