实验测试了一下 mysql 的 varchar 的最大有效长度.

2017-09-21 09:44:07 +08:00
 jin7

latin1 字符集, 65532

utf8 字符集, 21844

utf8mb4 字符集, 16128

也就是说如果设定为 utf8mb4 字符集, varchar 最多能存 16128 个字符, 不论是中文还是英文.

(65535-1-2)/1=65532

(65535-1-2)/3=21844

(65535-1-2)/4=16383 !=16128, 不满足这个"公式"

官方文档: https://dev.mysql.com/doc/refman/5.7/en/char.html

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.

6024 次点击
所在节点    MySQL
10 条回复
jin7
2017-09-21 09:46:43 +08:00
对了, mysql 版本是 5.7.17, 存储引擎是 innodb
jin7
2017-09-21 09:59:27 +08:00
soli
2017-09-21 10:31:47 +08:00
有用。谢谢。
iwishing
2017-09-21 17:16:27 +08:00
16383-16128=255
你试试看只有一个 colume,能有多长?
iwishing
2017-09-22 12:40:08 +08:00
http://img.vim-cn.com/40/aefbf9e17f48daf8a6c758a1202f4de5a67342.png

which is shared among all columns, 所有列都共享这个长度
jin7
2017-09-23 13:50:54 +08:00
我回去试试哈
jin7
2017-09-27 00:46:47 +08:00
@iwishing 确实是这样哈.
jin7
2017-09-27 00:47:56 +08:00
@iwishing 65,535 bytes, which is shared among all columns
之前是我没看明白这句话.
jin7
2017-09-27 00:48:10 +08:00
@iwishing 多谢
mysql
2017-10-01 10:13:34 +08:00
感谢分享

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/392447

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX