Jump to: navigation, search

Mysql MD5

From w3cyberlearnings

Contents

MySQL MD5 Function

This function calculates an MD5 128 bit checksum for a string, and it returns as a 32 hex digits binary string.

Syntax MD5

  • str: string to MD5
MD5(str);

NOte

MD5 value stores in BINARY(16) column.

Example 1

mysql> SELECT MD5('great leader');
+----------------------------------+
| MD5('great leader')              |
+----------------------------------+
| 5f2a13a9eb2d0149fa5dbe95457ce796 | 
+----------------------------------+
1 row in set (0.00 sec)

Example 2

mysql> INSERT INTO userpassword(username,password)
    -> VALUES('King',MD5('lovely world'));
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM userpassword;
+----+----------+----------------------------------+
| id | username | password                         |
+----+----------+----------------------------------+
|  1 | King     | 1533bdad3c7321f0a320244a075db787 | 
+----+----------+----------------------------------+
1 row in set (0.00 sec)

mysql> SELEcT * FROM userpassword WHERE password=MD5('lovely word');
Empty set (0.00 sec)

mysql> SELEcT * FROM userpassword WHERE password=MD5('lovely world');
+----+----------+----------------------------------+
| id | username | password                         |
+----+----------+----------------------------------+
|  1 | King     | 1533bdad3c7321f0a320244a075db787 | 
+----+----------+----------------------------------+
1 row in set (0.00 sec)


Related Links


Navigation
Web
SQL
MISC
References