function md5()

Using MD5 function in MySQL

Using the MD5 algorithm in MySQL is very easy because it has a native MD5() function.
The value is returned as a string of 32 hexadecimal digits, or NULL if the argument was NULL.
The return value is a string in the connection character set.

Syntax:

MD5(string)

Basic example:

mysql> SELECT MD5('Hello world!');

The above example will output:

86fb269d190d2c85f6e0468ceca42a20

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.

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

Example #2 will output:

a17602be9d6201a338243d8d7693f5bf

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 MySQL:

MySQL.com