MySQL VARCHAR大小限制 [英] MySQL VARCHAR size limit

查看:119
本文介绍了MySQL VARCHAR大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在表中的列的字段类型为VARCHAR(15),并且如果我尝试插入长度为16的数据,则MySQL会给出错误提示

If I have a column in table with field of type VARCHAR(15) and if I try to insert data of length 16, MySQL gives an error stating

Data too long for column 'testname' at row 1

有人知道为什么MySQL中的VARCHAR字段采用固定长度吗?另外,根据给定的大小,每条记录的VARCHAR字段会占用多少字节?

Does anyone know why VARCHAR fields in MySQL take fixed length? Also how many bytes does a VARCHAR field take per record based on the size given?

推荐答案

如果将列设置为varchar(15),则允许的最大字节数为15.因此,如果不将列修改为,则不能将其传递超过15个字符.支持超过15个.如果存储4个字符串,则只能使用可能的15个字节中的大约4个字节;而如果使用char(15),它将用其余11个字节填充空字节.

If you set a column to be varchar(15) the maximum bytes allowed is 15. Thus you can't pass it more than 15 characters without modifying the column to support more than 15. If you store a 4 character string it should only use around 4 bytes out of a possible 15, whereas if you used char(15) it would have filled in the other 11 with empty bytes.

http://dev.mysql.com/doc/refman/5.0/en/char.html

(我的字节计算可能已关闭,因为它始终为-1/+ 1或类似的值.)

( My byte calculation was probably off since it's always -1/+1 or something like that ).

这篇关于MySQL VARCHAR大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆