Don’t use large BLOBs in MySQL from Java

The MySQL database can store large chunks of binary data (up to 1 GB) using the BLOB data types.

However, this does not work well if you access the MySQL database from Java (or any other JVM based language) using the MySQL JDBC driver.

The JDBC API supports an efficient stream based way to handle BLOBs, but the MySQL JDBC driver does not implement this properly. It works, but it will buffer all data in memory in a way which is very inefficient and can make your JVM run out of memory if the BLOBs are large.

A good rule of thumb is to not store any objects larger than 64 KB in MySQL. Store such objects as files outside of the database instead. So never use the MEDIUMBLOB, LONGBLOB, MEDIUMTEXT or LONGTEXT data types.

(I am not sure whether this advise is only valid for JVM, or for usage of MySQL from other environments as well.)

This entry was posted in database, Java. Bookmark the permalink.

2 Responses to Don’t use large BLOBs in MySQL from Java

  1. Pingback: Don't use large BLOBs in MySQL from Java – Mikael Ståldal « SSHlab.com

  2. Hurrah! At last I got a webpage from where I know
    how to actually obtain useful facts regarding my study and knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



(this is a captcha)