I'm trying to store binary data as a blob in a MySQL table. I'm aware that my server is configured with a max_allowed_packet
size of 1M so I'm chunking the data into blobs of 1M. However I still see errors like this:
Exception: Packet for query is too large (1851203 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
What appears to be happening is the PreparedStatement
is escaping the data in my chunked blob.
e.g. blob 0000
would get sent as \0\0\0\0
.
So in the worst case data may be doubling in size which causes the error.
My only thought is to chunk the data into half the max_allowed_packet
size to leave space for potential escape characters.
Is there a better way? Should I pre-escape my data before I chunk it?