Search the MySQL manual:
Subscribe to the monthly
MySQL Newsletter!

6.2.3.2 Типы данных BLOB и TEXT

Тип данных BLOB представляет собой двоичный объект большого размера, который может содержать переменное количество данных. Существуют 4 модификации этого типа - TINYBLOB, BLOB, MEDIUMBLOB и LONGBLOB, отличающиеся только максимальной длиной хранимых величин. See section 6.2.6 Требования к памяти для различных типов столбцов.

Тип данных TEXT также имеет 4 модификации - TINYTEXT, TEXT, MEDIUMTEXT и LONGTEXT, соответствующие упомянутым четырем типам BLOB и имеющие те же максимальную длину и требования к объему памяти. Единственное различие между типами BLOB и TEXT состоит в том, что сортировка и сравнение данных выполняются с учетом регистра для величин BLOB и без учета регистра для величин TEXT. Другими словами, TEXT - это независимый от регистра BLOB.

Если размер задаваемого в столбце BLOB или TEXT значения превосходит максимально допустимую длину столбца, то это значение соответствующим образом усекается.

В большинстве случаев столбец TEXT может рассматриваться как столбец VARCHAR неограниченного размера. И, аналогично, BLOB - как столбец типа VARCHAR BINARY. Различия при этом следующие:

В MyODBC величины типа BLOB определяются как LONGVARBINARY и величины типа TEXT - как LONGVARCHAR.

Так как величины типов BLOB и TEXT могут быть чрезмерно большими, при их использовании целесообразно предусмотреть некоторые ограничения:

Следует учитывать, что внутренним представлением любой величины типа BLOB или TEXT является отдельно размещенный объект - в противоположность всем остальным типам столбцов, для которых память выделяется единовременно для столбца при открытии таблицы.

User Comments

Posted by [name withheld] on October 20 2003 5:59am[Delete] [Edit]

if we really go for up to 4 GB LONGBLOBS, some hints how to deal with your RAM that is most likely a lot smaller (http://bugs.mysql.com/bug.php?id=1605)
and what to do when the communication gets interrupted (http://bugs.mysql.com/1606) - this not being that unlikely in presence of such large amounts of data - would be usefull

Posted by Daniel Applebaum on January 15 2004 11:05am[Delete] [Edit]

I retrieve large BLOBs by using repeatedly retrieving only sections of the BLOB
using substring, ie:
select substring(document, 1, 10240) from documents where docid='3';
and then
select substring(document, 10241, 10240) from documents where docid='3';
etc.
My servlet turns around and immediately writes the partial response to the
client so even the servlet does not need to allocate very much memory. In
practice, I use 10MB partial queries.

Posted by [name withheld] on February 10 2004 1:04am[Delete] [Edit]

How about a blob example? How does one get a binary into it? Is it like an attachment? I think I am probably not the only one who is puzzled.

Posted by [name withheld] on March 7 2004 4:29pm[Delete] [Edit]

Storing large files in a longblob I find is a bad idea. For a better implementation of mysql binary storage (in PHP, but concept could be implemented in any language) checkout this article:

http://php.dreamwerx.net/forums/viewtopic.php?t=6


Posted by andrei none on March 9 2004 5:38pm[Delete] [Edit]

Yes i would love to see some examples too, i have been trying to figure out a way to insert data into a text or blob but unsuccessfully.

Posted by [name withheld] on March 20 2004 12:46am[Delete] [Edit]

I don't understand the purpose of storing large amounts of data in a database. The host I'm using allows me 500MB of disk space and 128MB of database space, so I suppose I'd be more interested in conserving my database space than disk space. :>

I'd sooner store the glut of info, binary or otherwise, in a disk file and reference its filename in whichever table(s) I need.

It might get a tad messy if large numbers of files are stored, but it might be worth any potential savings in time, processing and headaches.

Add your own comment.