I want to load a binary file into mysql database but I am very confused as loading data is usually done as a string
For example, A 14-bytes file that looks like (in hex)
00 01 2C 00 00 FF FF 0A
00 02 2C AB CD EF 00 0A
I want to load it in a table as follows
CREATE TABLE IF NOT EXISTS testtable
(
id smallint unsigned primary key,
data VARCHAR(4),
);
but when I use the following query for loading
LOAD DATA INFILE '/path/to/file' into table testtable CHARACTER SET UTF8 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
I get this error:
ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'
My question: is there a solution to encode the first two bytes as a smallint and store them in id column?
Note : 0x2C is the , and 0x0A is the \n as specified in the query
Many thanks