tags:

views:

573

answers:

2

How can I insert huge BLOBs into a MySQL database (InnoDB)?

Fields of type LONGBLOB support data sizes of up to 4 GB according to the MySQL manual. But how does data of such a huge size get into the database?

I tried to use

INSERT INTO table (bindata) VALUES ( LOAD_FILE('c:/tmp/hugefile') );

which fails if the size of hugefile is bigger than about 500 MB. I have set max_allowed_packet to an appropriate size; the value of innodb_buffer_pool_size doesn't seem to have an influence.

My server machine runs Windows Server 2003 and has 2 GB RAM. I'm using MySQL 5.0.74-enterprise-nt.

A: 

BLOB's are being cached in memory, that's why you will have 3 copies of a BLOB as you are inserting it into a database.

Your 500 MB BLOB occupies 1500 MB in RAM, which seems to hit your memory limit.

Quassnoi
So i need a 64Bit machine w/ >12GB of RAM to be able to insert 4 GB BLOBs?
oli_arborum
@oli_arborum: Seems like that. See here: http://www.mysql.com/news-and-events/newsletter/2003-09/a0000000237.html
Quassnoi
A: 

I do not know which client/api you use, but when trying to use blobs from own Java and Objective-C clients it seems, MySQL does not really support streaming of blobs. You need enough memory to hold the whole blob as byte array in ram (server and client side) more than once! Moving to a 64 bit linux helps, but is not desired solution.

MySQL ist not made for BLOB handling (ok for small BOBs :-). It occupies twice or three times the ram to be stored/read in the "BLOB".

You have to use an other database like PostgreSQL to get real BLOB support, sorry.

Arne Burmeister
In order not to need sizeof(BLOB) RAM on the client, I used the mysql command-line client and the LOAD_FILE() function, which only uses server's RAM.
oli_arborum