-2

How to insert binary and varbinary datat in MySQL? Need an example

create table string_binary1 (binarydata binary(3));

insert into string_binary1 values ('a');

insert into string_binary1 values ('12343');

difference between above 2 statements, whether in both the cases data is converted to binary. If so then , it is displayed as BLOB

but if I uncheck , treat binary/varbinary as non binary charater string, then only data is displayed properly but not in binary value.

Shiv_k
  • 89
  • 1
  • 5

1 Answers1

0

You can simpply use quotes to insert the data:

INSERT INTO varbinaryt1 (varbinarydata ) VALUES('myvarbinarydata')

See the MySQL docs:

When BINARY values are stored, they are right-padded with the pad value to the specified length. The pad value is 0x00 (the zero byte). Values are right-padded with 0x00 on insert, and no trailing bytes are removed on select. All bytes are significant in comparisons, including ORDER BY and DISTINCT operations. 0x00 bytes and spaces are different in comparisons, with 0x00 < space.

Example: For a BINARY(3) column, 'a ' becomes 'a \0' when inserted. 'a\0' becomes 'a\0\0' when inserted. Both inserted values remain unchanged when selected.

For VARBINARY, there is no padding on insert and no bytes are stripped on select. All bytes are significant in comparisons, including ORDER BY and DISTINCT operations. 0x00 bytes and spaces are different in comparisons, with 0x00 < space.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331