8

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.

2
  • Just because you can doesn't mean you should. Commented Jun 3, 2009 at 15:43
  • 4
    @kekoav I know that in certain environments it is be better to store files in filesystem than in DB, but independent of this discussion I must know how it works to store data like this in order to be able to try it and form an opinion on advantages and disadvantages of both solutions (storing in filesystem and storing in DB). Thank you for your understanding in advance! Commented Jun 3, 2009 at 15:49

2 Answers 2

3

BLOBs are 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 1,500 MB in RAM, which seems to hit your memory limit.

Sign up to request clarification or add additional context in comments.

4 Comments

So i need a 64Bit machine w/ >12GB of RAM to be able to insert 4 GB BLOBs?
@oli_arborum: Seems like that. See here: mysql.com/news-and-events/newsletter/2003-09/a0000000237.html
"MySQL supports BLOBs (Binary Large Objects), which means you can store any binary file into MySQL. Many people ask, what is the maximum size of a BLOB in MySQL. The theoretical limit in MySQL 4.0 is 2G, however each blob requires generally to have 3 copies of it in the memory (stored in various buffers) so you need a lot of memory, if you have large BLOBs stored in MySQL. This is the reason, why the theoretical limit can be reached only on 64bit systems. The Practical limits are around some hundreds of megs per BLOB." - Last available archive.org snapshot 20100208201732
Still online at mailing list archive nyphp.org/pipermail/talk/2003-September/005737.html.
1

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 is not made for BLOB handling (ok for small BLOBs :-). It occupies twice or three times the ram to be stored/read in the "BLOB".

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.