- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
根据定义:
VARCHAR: The range of Length is 1 to 255 characters. VARCHAR values are sorted and compared in case-insensitive fashion unless the BINARY keyword is given. x+1 bytes
TINYBLOB, TINYTEXT: A BLOB or TEXT column with a maximum length of 255 (2^8 - 1) characters x+1 bytes
所以基于此,我创建了下表:
CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255),
`lastname` tinytext,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
或者创建一个 varchar 或 tinytext 以及为什么更好?
是否也一样:
VARCHAR: The range of Length is > 255 characters. VARCHAR values are sorted and compared in case-insensitive fashion unless the BINARY keyword is given. x+2 bytes
BLOB, TEXT A BLOB or TEXT column with a maximum length of 65535 (2^16 - 1) characters x+2 bytes
最佳答案
在这种情况下 varchar
更好。
请注意,varchar
可以是 1 到 65535 个字符。
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. See Section E.7.4, “Table Column-Count and Row-Size Limits”.
Blob 保存在文件的单独部分中。
它们需要额外的文件读取才能包含在数据中。
因此,获取 varchar 的速度要快得多。
如果您有一个不常访问的大型 blob,那么 blob 更有意义。
将 blob 数据存储在单独的(部分)文件中可以让您的核心数据文件更小,从而更快地获取。
关于mysql - varchar(255) vs tinytext/tinyblob 和 varchar(65535) vs blob/text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7755629/
这是我之前问题的跟进:Blob and Storage Requirement 我使用 SHOW TABLE STATUS 进行了一些测试,发现实际使用的总磁盘空间仅取决于上传到数据库的实际文件的大小
如何使字段成为 BLOB 而不是 TINYBLOB? 我的映射如下: private byte[] ImageBytes; public BufferedImage getImage() {
我尝试从数据库 (blob) 中读取图像,但我遇到了问题,因为我不知道图像的 mime 类型。我只有 tinyblob。 我可以读取图像并将其保存回我的硬盘吗? 最佳答案 最好的解决方案是在将图像插入
好吧,我的问题很愚蠢。 在 Hibernate 5.1(5.2 相同)中,我的 Year 列映射到tinyblob,而不是人们所期望的直观的 int 列。其他 JSR-310 列已成功映射。 例如 @
我的附带问题是 tinyblob 和 tinytext 之间真的有什么区别吗? 相信我真正的问题是什么原因,如果有的话,我会选择 varchar(255) 而不是 tinyblob 或 tinytex
对于我正在创建的包含 IP 范围的表,我需要在 MySQL 记录中存储两个 128 位(16 字节)int 值。由于 MySQL 仅支持最多 8 字节的整数,因此我发现我需要使用二进制列 (tinyb
我正在处理一些使用 java8、hibernate5、spring 等的遗留应用程序。我想做的是包含 hibernate-java8 模块以启用 java.time 对象的正确使用,没有任何映射器、转
我有一个使用 Hibernate 映射到数据库的 bean。我正在使用 Hibernate Annotations 来指示我想要的映射,并创建索引。彻底简化的代码如下所示。 我遇到的问题是我的 byt
根据定义: VARCHAR: The range of Length is 1 to 255 characters. VARCHAR values are sorted and compared in
我有一个带有 java.time.Instant 类型的 @Column 的 JPA @Entity。我的理解是这应该映射到 TIMESTAMP 的列类型。但是,Hibernate 自动更新创建了类型
我是一名优秀的程序员,十分优秀!