Home >Database >Mysql Tutorial >mysql varchar和char创建索引的大小计算_MySQL

mysql varchar和char创建索引的大小计算_MySQL

WBOY
WBOYOriginal
2016-06-01 13:38:471460browse

bitsCN.com


mysql varchar和char创建索引的大小计算

 

mysql 在varchar 创建索引时,  

会根据字符集和定义的字符多少来决定占用字节的多少

 

如果为varchar(20) charset = utf8

那么key_len 就为63

20 * 3 + 1 (是否为空的标识)+2 (字符长度多少)

 

如果为char(20) charset = gbk

那么key_len 就为41

20 * 2 + 1 (是否为空的标识)

 

如果为varchar(20) not null charset = utf8

那么key_len 就为62

20 * 3 + 2 (字符长度多少)

 

如果为char(20) not null charset = gbk

那么key_len就为40

20*2=40

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn