Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Varbinary vs Blob in MySQL

Tags:

mysql

binary

blob

I have about 2k of raw binary data that I need to store in a table, but don't know whether to choose the Varbinary or Blob type. I have read through the descriptions in the MySQL docs but didn't find any contract and compare descriptions. I also read that varbinary only supports up to 255 characters, but I successfully created a varbinary(2048) field, so I'm a bit confused.

The binary data does not need to be indexed, nor will I need to query on it. Is there an advantage to using one type over the other from PHP?

Thanks!

like image 518
Jimmyb Avatar asked Dec 12 '11 15:12

Jimmyb


People also ask

What is VARBINARY in MySQL?

The VARBINARY type is similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings. M represents the maximum column length in bytes. It contains no character set, and comparison and sorting are based on the numeric value of the bytes.

What is a BLOB in MySQL?

A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB , BLOB , MEDIUMBLOB , and LONGBLOB . These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT , TEXT , MEDIUMTEXT , and LONGTEXT .

What is difference between BLOB and TEXT in MySQL?

BLOB stands for Binary Large Objects and as its name suggests, it can be used for storing binary data while TEXT is used for storing large number of strings. BLOB can be used to store binary data that means we can store pictures, videos, sounds and programs also.

What does VARBINARY mean in SQL?

VarBinary is a variable width data type. The syntax for declaring Binary variable is varbinary(n) , where n defines the maximum size in bytes. The varbinary data type uses actual length of the data entered + 2 bytes as the storage.


1 Answers

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.

like image 132
Romain Avatar answered Sep 23 '22 15:09

Romain