MySQL: Large VARCHAR vs. TEXT?(MySQL:大 VARCHAR 与文本?)
问题描述
我在 MySQL 中有一个消息表,用于记录用户之间的消息.除了典型的 id 和消息类型(所有整数类型),我需要将实际的消息文本保存为 VARCHAR 或 TEXT.我将前端限制设置为 3000 个字符,这意味着消息将永远不会插入到数据库中超过此长度.
I've got a messages table in MySQL which records messages between users. Apart from the typical ids and message types (all integer types) I need to save the actual message text as either VARCHAR or TEXT. I'm setting a front-end limit of 3000 characters which means the messages would never be inserted into the db as longer than this.
使用 VARCHAR(3000) 或 TEXT 是否有理由?仅仅编写 VARCHAR(3000) 有点违反直觉.我已经阅读过 Stack Overflow 上的其他类似帖子,但如果能获得特定于此类常见消息存储的视图会很好.
Is there a rationale for going with either VARCHAR(3000) or TEXT? There's something about just writing VARCHAR(3000) that feels somewhat counter-intuitive. I've been through other similar posts on Stack Overflow but would be good to get views specific to this type of common message storing.
推荐答案
TEXT和BLOB可以存储在表外,而表只有一个指向实际存储位置的指针.它的存储位置取决于很多因素,例如数据大小、列大小、row_format 和 MySQL 版本.TEXTandBLOBmay by stored off the table with the table just having a pointer to the location of the actual storage. Where it is stored depends on lots of things like data size, columns size, row_format, and MySQL version.VARCHAR与表内联存储.VARCHAR在大小合理时更快,权衡更快取决于您的数据和您的硬件,您希望使用您的数据对实际场景进行基准测试.VARCHARis stored inline with the table.VARCHARis faster when the size is reasonable, the tradeoff of which would be faster depends upon your data and your hardware, you'd want to benchmark a real-world scenario with your data.这篇关于MySQL:大 VARCHAR 与文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL:大 VARCHAR 与文本?
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
