MySQL - Char 和 Varchar 之间的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3887735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:22:58  来源:igfitidea点击:

MySQL - Difference between Char and Varchar?

mysql

提问by HELP

Possible Duplicate:
What's the difference between VARCHAR and CHAR?

可能的重复:
VARCHAR 和 CHAR 之间有什么区别?

what is the difference between CHAR and VARCHAR.

CHAR 和 VARCHAR 有什么区别。

回答by Mark Byers

A CHAR field is a fixedlength, and VARCHAR is a variablelength field.

CHAR 字段是固定长度,而 VARCHAR 是可变长度字段。

This means that the storage requirements are different - a CHAR always takes the same amount of space regardless of what you store, whereas the storage requirements for a VARCHAR vary depending on the specific string stored.

这意味着存储要求是不同的 - 无论您存储什么,CHAR 始终占用相同的空间量,而 VARCHAR 的存储要求因存储的特定字符串而异。

回答by BoltClock

VARCHARstores a variable number of bytes for only the space required by the content.

VARCHAR仅为内容所需的空间存储可变数量的字节。

CHARstores a fixed size of however many bytes you specify for your table, no matter how many characters occupy a field of this type per row.

CHAR存储您为表指定的固定大小的字节数,无论每行有多少字符占用此类型的字段。