MySQL > = 5.6.1
In MySQL, encoding or decoding in BASE64 is only possible from version 5.6.1. Previous versions give the following error:
#1305 - FUNCTION impor_website_2014.TO_BASE64 does not exist
The functions introduced in the above version were:
TO_BASE64 ()
Converts the argument to a base-64 encoded form and returns the result as a string with the character and collation data base. If the argument is not a string , it is converted to string before conversion. The result is NULL if the argument is NULL .
FROM_BASE64 ()
It takes a string encoded with the base-64 rules used by TO_BASE64()
and returns the decoded result as a binary string . The result is NULL if the argument is NULL or not a string on base-64.
Usage example:
SELECT TO_BASE64('abc'), FROM_BASE64(TO_BASE64('abc')); # Devolve: 'JWJj', 'abc'
MySQL < 5.6.1
There is a project in GitHub to resolve encoding and decoding in BASE64 for older versions of MySQL:
It is essentially a UDF User Defined Function that aims to create the functions: base64encode()
and base64decode()
.
Usage example:
SELECT base64encode('data,binary,text,...');
SELECT base64decode('b64strings');
INSERT INTO t1 (body) VALUES (base64encode('something'));
In order to use, you have to do the build and the activation:
Build
$ git clone https://github.com/y-ken/mysql-udf-base64.git
$ cd mysql-udf-base64
$ gcc -Wall -fPIC -I/usr/local/include -shared base64.c -o base64.so
$ sudo install -m 755 base64.so 'mysql_config --plugindir'
Activation
mysql> CREATE FUNCTION base64encode RETURNS STRING SONAME 'base64.so';
mysql> CREATE FUNCTION base64decode RETURNS STRING SONAME 'base64.so';
Examples and method for building and activating removed from GitHub from project page .
/ sup>
Note:
It should be noted that this answer aims to deal with the problem exposed: The use of a function and the fact that it is giving an error when trying to use it.
Base64 does not produce the result described in the , Base64 is not encryption, it is just the conversion of the string to a standard radix-64 commonly used to standardize characters, such as the case of transferring images between different systems. Any Encode system that has the Decode method should not be used for passwords.