Search code examples
mysqlencryptiontextaesvarbinary

How do I use varbinary if I don't know the length of my text


I want to encrypt text using AES in mysql, but I have a small problem, because you need to use varbinary to store these.

Some of my datatypes are varchar and yes I can probably work out the length of my varbinary for these. However for my address fields I use the TEXT datatype, as we have Chinese addresses stored and these can be very long. I use the TEXT datatype because you do not need to specify a length in mysql.

The problem is that with varbinary you need to specify a length, and I don't really know the length because the addresses can be of any length.

Is there some kind of binary datatype I can use for AES where I don't have to specify the length of the data?


Solution

  • As per comments - you require BLOB data type, which is short for Binary Large Object (thanks Maarten Bodewes for clarification).

    A BLOB data type won't store character set with the information and is equivalent to TEXT type, without a charset. As mentioned in the comments, there are other types such as MEDIUMBLOB, TINYBLOB, LARGEBLOB, they are all covered on MySQL's manual page.