V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
jin7
V2EX  ›  MySQL

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

  •  
  •   jin7 · 2017-09-21 09:44:07 +08:00 · 5996 次点击
    这是一个创建于 2380 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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.

    10 条回复    2017-10-01 10:13:34 +08:00
    jin7
        1
    jin7  
    OP
       2017-09-21 09:46:43 +08:00
    对了, mysql 版本是 5.7.17, 存储引擎是 innodb
    jin7
        2
    jin7  
    OP
       2017-09-21 09:59:27 +08:00
    soli
        3
    soli  
       2017-09-21 10:31:47 +08:00
    有用。谢谢。
    iwishing
        4
    iwishing  
       2017-09-21 17:16:27 +08:00
    16383-16128=255
    你试试看只有一个 colume,能有多长?
    iwishing
        5
    iwishing  
       2017-09-22 12:40:08 +08:00   ❤️ 1
    http://img.vim-cn.com/40/aefbf9e17f48daf8a6c758a1202f4de5a67342.png

    which is shared among all columns, 所有列都共享这个长度
    jin7
        6
    jin7  
    OP
       2017-09-23 13:50:54 +08:00
    我回去试试哈
    jin7
        7
    jin7  
    OP
       2017-09-27 00:46:47 +08:00
    @iwishing 确实是这样哈.
    jin7
        8
    jin7  
    OP
       2017-09-27 00:47:56 +08:00
    @iwishing 65,535 bytes, which is shared among all columns
    之前是我没看明白这句话.
    jin7
        9
    jin7  
    OP
       2017-09-27 00:48:10 +08:00
    @iwishing 多谢
    mysql
        10
    mysql  
       2017-10-01 10:13:34 +08:00
    感谢分享
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   960 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:32 · PVG 04:32 · LAX 13:32 · JFK 16:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.