Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query BINARY fields in MySQL?

Tags:

mysql

I'm trying to SELECT data from a table that stores Java UUIDs as binary(16).

For example, the UUID 76572de1-aa8c-435b-afe4-8e260e19466b looks like this in phpMyAdmin: 0x76572de1aa8c435bafe48e260e19466b.

Now, how can I query any values from that table by using a simple string?:

  • SELECT ... WHERE uuid = '76572de1-aa8c-435b-afe4-8e260e19466b'
  • SELECT ... WHERE uuid = '76572de1aa8c435bafe48e260e19466b'
  • SELECT ... WHERE uuid = '0x76572de1-aa8c-435b-afe4-8e260e19466b'
  • SELECT ... WHERE BINARY uuid = '76572de1aa8c435bafe48e260e19466b'
  • SELECT ... WHERE BINARY uuid = '76572de1-aa8c-435b-afe4-8e260e19466b'
  • and a lot of other things utilizing CONVERT or BINARY keywords
like image 543
K. D. Avatar asked Oct 28 '25 17:10

K. D.


1 Answers

Hexadecimal literals in MySQL look like this: X'01AF' or this: 0x01AF (case insensitive in both cases.

One option would be SELECT ... WHERE uuid = X'76572de1aa8c435bafe48e260e19466b'

like image 200
gandaliter Avatar answered Oct 30 '25 07:10

gandaliter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!