mysql - varchar(limit) 是如何工作的?

标签 mysql sql varchar

我一直在使用 MySQL,并且非常模糊地理解 VARCHAR(This Number Here) 部分。该数字是该列可以存储的字符总数吗?

例如,假设我有一个 VARCHAR(400) latin1_general_ci,400 是否意味着字符串的 400 字节限制,或者字符串可以有 400 个字符?我可以在该列变量中存储多大的字符串?

最佳答案

这是字段的最大字符串长度(请参阅 here )(不是字节):

The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters.

无论编码如何,都允许 30 个字符。

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.

关于mysql - varchar(limit) 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35566648/

相关文章:

java - 从 mysql 表读取时出错

sql - 将执行动态查询的结果插入表中

python - MySQL VarChar 255 及以上

postgresql - 我如何知道我的 PostgreSQL 服务器是否使用 "C"语言环境?

php - 查询一个Mysql数据库的多个表

php - 文件上传错误

php 文件文本,每次在 mysql 基值数据中添加一行

mysql - 使用 SELECT * 创建 MYSQL View

迄今为止的 SQL VarChar

mysql - 如何从excel 2011连接到mysql