Menu

Toshimaru's Blog

Convert String to Hex in MySQL

Environment

  • mysql 5.7

String to Hex

Use HEX to convert string to hex.

 select 'cat', HEX('cat');
+-----+------------+
| cat | HEX('cat') |
+-----+------------+
| cat | 636174     |
+-----+------------+

Hex to String

Use X'' or UNHEX() to convert hex to string.

select 'cat', X'636174', UNHEX(636174);
+-----+-----------+---------------+
| cat | X'636174' | unhex(636174) |
+-----+-----------+---------------+
| cat | cat       | cat           |
+-----+-----------+---------------+

Reference

Load more