char与varchar的区别与联系

char是字节类型,varcahr是字符类型

1、char(20) 

存放的是字节,utf-8中文字符占三个字节,GB18030兼容GBK兼容GB2312中文字符占两个字节,ISO8859-1是拉丁字符(ASCII字符)占一个字节

2、varcahr(20) 

存放是字符,mysql4.0以下存放是字节,5.0存放是字符。

    最大长度:  MySQL要求一个行定义长度不能超过65535个字节,不包括text、blob等大字段类型,varchar长度受此长度限制,和其他非大字段加起来不能超过65535个字节.

举例说明:

create table test1111(

 id char(255) null,

content varchar(21850) null

)ENGINE=InnoDB DEFAULT CHARSET=utf8;

就会报错:

   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

猜你喜欢

转载自www.cnblogs.com/dsxStudyNote/p/sql.html