> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# from_binary

> Converts a binary value to a VARCHAR string based on the specified binary format (binary_type).

Converts a binary value to a VARCHAR string based on the specified binary format (`binary_type`). The following binary formats are supported: `hex`, `encode64`, and `utf8`. If no `binary_type` is specified, `hex` is the default.

## Syntax

```Haskell theme={null}
from_binary(binary[, binary_type])
```

## Parameters

* `binary`: the input binary to convert, required.

* `binary_type`: the binary format for conversion, optional.

  * `hex` (default): `from_binary` uses the `hex` method to encode the input binary to a VARCHAR string.
  * `encode64`: `from_binary` uses the `base64` method to encode the input binary to a VARCHAR string.
  * `utf8`: `from_binary` converts the input binary to a VARCHAR string without any transformation.

## Return value

Returns a VARCHAR string.

## Examples

```Plain theme={null}
mysql> select from_binary(to_binary('ABAB', 'hex'), 'hex');
+----------------------------------------------+
| from_binary(to_binary('ABAB', 'hex'), 'hex') |
+----------------------------------------------+
| ABAB                                         |
+----------------------------------------------+
1 row in set (0.02 sec)

mysql> select from_base64(from_binary(to_binary('U1RBUlJPQ0tT', 'encode64'), 'encode64'));
+-----------------------------------------------------------------------------+
| from_base64(from_binary(to_binary('U1RBUlJPQ0tT', 'encode64'), 'encode64')) |
+-----------------------------------------------------------------------------+
| STARROCKS                                                                   |
+-----------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> select from_binary(to_binary('STARROCKS', 'utf8'), 'utf8');
+-----------------------------------------------------+
| from_binary(to_binary('STARROCKS', 'utf8'), 'utf8') |
+-----------------------------------------------------+
| STARROCKS                                           |
+-----------------------------------------------------+
1 row in set (0.01 sec)

```

## References

* [to\_binary](/documents/4.2/sql-reference/sql-functions/binary-functions/to_binary.md)
* [BINARY/VARBINARY data type](/documents/4.2/sql-reference/data-types/string-type/BINARY.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.