function md5()

Using MD5 function in MariaDB

Using the MD5 algorithm in MariaDB is very easy because it has a native MD5() function.

The return value is a 32-hex digit string, and as of MariaDB 5.5, is a nonbinary string in the connection character set and collation, determined by the values of the character_set_connection and collation_connection system variables. Before 5.5, the return value was a binary string.

NULL is returned if the argument was NULL.



Basic example:

SELECT MD5('Hello world!');

The above example will output:


Example #2 with salt before string to be encrypted:

In some cases, it is worth using a salted MD5 hash for added security. This means that you add the "salt string" before or after the string to be encrypted.

            SELECT MD5(CONCAT('yourSalt', 'Hello world!'));

Example #2 will output:


Note: Be aware that using encryption functions in a database usually means that the original, unencrypted text will be stored in the database log, which in some cases can be a potential security risk.

External resources about MD5 in MariaDDB: