Varbinary vs Blob in MySQL

最后都变了- 提交于 2019-12-03 04:35:58

VARBINARY is bound to 255 bytes on MySQL 5.0.2 and below, to 65kB on 5.0.3 and above.

BLOB is bound to 65kB.

Ultimately, VARBINARY is virtually the same as BLOB (from the perspective of what can be stored in it), unless you want to preserve compatibility with "old" versions of MySQL. The MySQL Documentation says:

In most respects, you can regard a BLOB column as a VARBINARY column that can be as large as you like.

Fernando Gonzalez Sanchez

Actually blob can be bigger (there are tinyblob, blob, mediumblob & longblob http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html) with up to 2^32 -1 on size limit.

Also blob storage grows "outside" of the row, while max varbinary size is tied by amount of free row size available (so it can actually be less than 64Kb).

There are some minor differences between both

1) With Index scripting (blob needs a prefix size on indexes, varbinary doesn't) http:/en/column-indexes.html
CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));

2) As already mentioned there are trailling space issues managed differently between varbinary & blob at MySql 5.0.x or earlier versions: http:///en/blob.html http:///en/binary-varbinary.html

(truncating the links, since stackoverflow thinks too many links are spam)

One significant difference is blob types are stored in secondary storage, while varbinaries are stored inline in the row in the same way as varchars and other "simple" types.

This can have an impact on performance in a busy system, where the additional lookup to fetch and manipulate the blob data can be expensive.

It is worth to point that Memory storage engine does not support BLOB/TEXT but it works with VARBINARY.

I am just looking at a test app that stores around 5k binary data in a column. It initially used varbinary but since it is so slow I decided to try blob. Well I'm looking at disk write speed with atop and can't see any difference.

The only significant difference I read in mysql manual is that blobs are unsupported by the memory engine so any temporary tables you create with queries (see when mysql uses temp tables) will be created on-disk and that is much slower. So you better bet on varbinary/binary if it is a short enough to fit into a row (at the moment 64k total for all columns).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!