What is the difference between "VARCHAR BINARY" and "VARBINARY" in MySQL?

I created the following test pattern:

CREATE TABLE t (
   a VARCHAR(32) BINARY,
   b VARBINARY(32)
);

INSERT INTO t (a, b) VALUES ( 'test    ', 'test    ');
INSERT INTO t (a, b) VALUES ( 'test    \0', 'test    \0');

But this query did not show the difference between the two types:

SELECT a, LENGTH(a), HEX(a), b, LENGTH(b), HEX(b) FROM t;

a          LENGTH(a)  HEX(a)              b          LENGTH(b)  HEX(b)              
---------  ---------  ------------------  ---------  ---------  --------------------
test               8  7465737420202020    test               8  7465737420202020    
test               9  746573742020202000  test               9  746573742020202000  
+4
source share
1 answer

Here is the difference I could find in the documentation:

VARCHAR BINARY

  • The BINARY attribute causes binary sorting for the character set of a column, and the column itself contains non-binary character strings, not binary byte strings.
  • When the BINARY values ​​are stored, they are entitled to add the pad value to the specified length.
  • BINARY , , , , .

VARBINARY

  • SQL , , , , .
  • , . .
  • , , , .
+3

All Articles