M is not specified, 1048576 is used by default. Unlike VARCHAR, whose maximum length increases in v4.2, the maximum BINARY/VARBINARY length remains 1048576 bytes. Binary data types contain byte strings while character data types contain character strings.
BINARY is an alias of VARBINARY. The usage is the same as VARBINARY.
Limits and usage notes
- VARBINARY columns are supported in Duplicate Key, Primary Key, and Unique Key tables. They are not supported in Aggregate tables.
- VARBINARY columns cannot be used as partition keys, bucketing keys, or dimension columns of Duplicate Key, Primary Key, and Unique Key tables. They cannot be used in ORDER BY, GROUP BY, and JOIN clauses.
- BINARY(M)/VARBINARY(M) are not right-padded in the case of unaligned length.
Examples
Create a column of VARBINARY type
When creating a table, use the keywordVARBINARY to specify column j as a VARBINARY column.
Load data and store it as BINARY type
The database supports the following ways to load data and store it as BINARY type.-
Method 1: Use INSERT INTO to write data to a constant column of BINARY type (such as column
j), where the constant column is prefixed withx''. -
Method 2: Use the to_binary function to convert VARCHAR data to binary data.
-
Method 3: Use Broker Load to load a Parquet or ORC file and store the file as BINARY data. For more information, see Broker Load.
- For Parquet files, convert
parquet::Type::type::BYTE_ARRAYtoTYPE_VARBINARYdirectly. - For ORC files, convert
orc::BINARYtoTYPE_VARBINARYdirectly.
- For Parquet files, convert
-
Method 4: Use Stream Load to load a CSV file and store the file as
BINARYdata. For more information, see Load CSV data.- CSV file uses the hex format for binary data. Please ensure the input binary value is a valid hex value.
BINARYtype is only supported in CSV file. JSON file does not supportBINARYtype.
t1is a table with a VARBINARY columnb.
Query and process BINARY data
The database supports querying and processing BINARY data, and supports the use of BINARY functions and operators. This example uses tabletest_binary.
Note: If you add the --binary-as-hex option When you access the database from your MySQL client, binary data will be displayed using hex notation.
Text