Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

mysql varchar实际存储位数

mysql 对于 varchr 类型,若位数小于 256,会多加一个字节存储(用来保存长度),大于 255 的会多加两个字节存储,详见 mysql 文档

VARCHAR(_`M`_), VARBINARY(_`M`_)
L + 1 bytes if column values require 0 ? 255 bytes, L + 2 bytes if values may require more than 255 bytes

为什么我用 LENGTH 函数得到的字节数没有加上呢?

SELECT LENGTH('a'); -- 1,为什么不是 2?
-- 从表字段里面计算也是一样的

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
LENGTH()方法是获取字符串长度,不是获取字节大小,谢谢,关注

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...