The BINARY function can be used in the following versions of MySQL:
MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23.3
Let's look at some MySQL BINARY function examples and explore how to use the BINARY function in MySQL.
Using the BINARY function to cast a value to a binary string is one way to force a byte-by-byte comparison of strings, rather than a character-by-character comparison. Let's investigate this further.
If we ran the example above, MySQL would perform a character-by-character comparison of 'AODBA' and 'AODBA' and return 1 (because on a character-by-character basis, 'AODBA' and 'AODBA' are equivalent).
However, if we modified the example by adding the BINARY function as follows, changing the comparison to byte-by-byte instead of character-by-character:
MySQL would perform a byte-by-byte comparison of 'AODBA' and 'AODBA' and would return 0 (because on a byte-by-byte basis, 'AODBA' and 'AODBA' are NOT equivalent.)