MySQL 中的 VARCHAR(255) 和 TINYTEXT 字符串类型有什么区别?

2021-12-25 00:00:00 types mysql

MySQL 中的 VARCHAR(255) 和 TINYTEXT 字符串类型有什么区别?

What's the difference between VARCHAR(255) and TINYTEXT string types in MySQL?

它们中的每一个都允许存储最大长度为 255 个字符的字符串.存储要求也相同.我什么时候应该更喜欢一个?

Each of them allows to store strings with a maximum length of 255 characters. Storage requirements are also the same. When should I prefer one over another?

推荐答案

您不能为 TINYTEXT 分配 DEFAULT 值,也不能在后者上创建无前缀索引.

You cannot assign a DEFAULT value to a TINYTEXT and you cannot create an unprefixed index on the latter.

在内部,额外的对象被分配到内存中来处理 TEXT(包括 TINYTEXT)列,这会导致大记录集上的内存碎片.

Internally, additional objects are allocated in memory to handle TEXT (incl. TINYTEXT) columns which can cause memory fragmentation on the large recordsets.

请注意,这仅涉及记录集中列的内部表示,而不涉及它们在磁盘上的存储方式.

Note that this only concerns the column's internal representation in the recordsets, not how they are stored on the disk.

相关文章