MySQL - Base64 vs BLOB MySQL - Base64 vs BLOB json json

MySQL - Base64 vs BLOB


JSON assumes utf8, hence is incompatible with images unless they are encoded in some way.

Base64 is almost exactly 8/6 times as bulky as binary (BLOB). One could argue that it is easily affordable. 3000 bytes becomes about 4000 bytes.

Everyone should be able to accept arbitrary 8-bit codes, but not everybody does. Base-64 may be the simplest and overall best compromise for not having to deal with 8-bit data.

Since these are "small", I would store them in a table, not a file. I would, however, store them in a separate table and JOIN by an appropriate id when you need them. This allows queries that don't need the image to run faster because they are not stepping over the BLOBs.

Technically, TEXT CHARACTER SET ascii COLLATE ascii_bin would do, but BLOB makes it clearer that there is not really any usable text in the column.


Why would you base64-encode the images on the wire? I think you're starting from a wrong assumption.


I don't see why the DB Server shouldn't always keep binary data in it's native form. Thus, use a BLOB.(But even if you did store the data in Base64 string, there is no need concern yourself about encoding/decoding performance because the IO's impact will be more significant.)

I don't get why the client should send the data in base64 though. Why not just "stream" it using a simple HTTP call?