How FROM_BASE64() Works in MariaDB

In MariaDB, FROM_BASE64() is a built-in string function that decodes the given base-64 encoded string.

It returns the result as a binary string.

Syntax

The syntax goes like this:

FROM_BASE64(str)

Where str is the base-64 encoded string to decode.

Example

Here’s a basic example:

SELECT FROM_BASE64('U2t1bGxkdWdnZXJ5');

Result:

+---------------------------------+
| FROM_BASE64('U2t1bGxkdWdnZXJ5') |
+---------------------------------+
| Skullduggery                    |
+---------------------------------+

Strings can be base-64 encoded with the TO_BASE64() function. Therefore, we can use the result we get here, and use TO_BASE64() to re-encode it to base-64:

SELECT TO_BASE64('Skullduggery');

Result:

+---------------------------+
| TO_BASE64('Skullduggery') |
+---------------------------+
| U2t1bGxkdWdnZXJ5          |
+---------------------------+

We can see that it results in the same base-64 encoded string that we decoded with FROM_BASE64().

Null Values

Providing null as an argument results in null:

SELECT FROM_BASE64(null);

Result:

+-------------------+
| FROM_BASE64(null) |
+-------------------+
| NULL              |
+-------------------+

Providing No Arguments

Calling FROM_BASE64() without passing any arguments results in an error:

SELECT FROM_BASE64();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'FROM_BASE64'