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.



Basic example:

mysql> 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.

            mysql> SELECT MD5(CONCAT('yourSalt', 'Hello world!'));
            mysql> SELECT MD5('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 MySQL: