How much UTF-8 text fits in a MySQL “Text” field?

后端 未结 3 1970
旧巷少年郎
旧巷少年郎 2020-12-08 02:24

According to MySQL, a text column holds 65,535 bytes.

So if this a legitimate boundary then will it actually only fit about 32k UTF-8 characters, right?

3条回答
  •  孤街浪徒
    2020-12-08 02:47

    However, when used as primary key, MySQL assumes that each limit of column's size adds 3 bytes to key.

    mysql> alter table test2 modify code varchar(333) character set utf8;
    Query OK, 0 rows affected (0.05 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> alter table test2 modify code varchar(334) character set utf8;
    ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes
    

    Well, using long string columns as primary key is generally a bed practice, however I've came across that problem when working with database of one commercial (!) product.

提交回复
热议问题