본문 바로가기

DB/Mysql

mysql md5 함수 사용


mysql에서 Text가 key가 되어야 할 경우 그에 대한 hash값을 사용하면 fixed_length로 key를 지정할 수 있다. 

아래는 mysql의 암호화와 압축 관련함수 페이지이다. 
http://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html 

MD5() Calculate MD5 checksum
OLD_PASSWORD() Return the value of the pre-4.1 implementation of PASSWORD
PASSWORD() Calculate and return a password string
SHA1()SHA() Calculate an SHA-1 160-bit checksum
SHA2() Calculate an SHA-2 checksum

< 사용법 > 

 MD5(str)

Calculates an MD5 128-bit checksum for the string. The value is returned as a string of 32 hex digits, or NULL if the argument was NULL. The return value can, for example, be used as a hash key. See the notes at the beginning of this section about storing hash values efficiently.

As of MySQL 5.5.3, the return value is a nonbinary string in the connection character set. Before 5.5.3, the return value is a binary string; see the notes at the beginning of this section about using the value as a nonbinary string.

mysql> SELECT MD5('testing');
        -> 'ae2b1fca515949e5d54fb22b8ed95575'

This is the “RSA Data Security, Inc. MD5 Message-Digest Algorithm.

See the note regarding the MD5 algorithm at the beginning this section.


그람 저렇게 긴게 다 필요하냐?  

아니라면  

필요한 부분만 잘라서 쓰면 된다. 왼쪽 10개 byte만 사용

mysql test -uroot -ptellme -e "select left(md5('asdf'),10)"

+----------------------+

| left(md5('asdf'),10) |

+----------------------+

| 912ec803b2           |

+----------------------+

 
허허허