Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MD5 function returns empty result

Tags:

mysql

md5

I am trying to return an MD5 encoded string of a value from my database, but it just returns a blank result (not null, just blank). I have tried just running this query and get the same result:

SELECT MD5('test');

I have tried restarting the MySQL server, MySQL Workbench, etc. But get the same result. If I try running the same command on a different database/server, it returns the hash string just fine.

What am I doing wrong? Is there a setting I disabled on accident?

like image 506
JimmyJammed Avatar asked Jan 18 '13 00:01

JimmyJammed


People also ask

What is the MD5 hash of an empty string?

The md5sum of "nothing" (a zero-length stream of characters) is d41d8cd98f00b204e9800998ecf8427e, which you're seeing in your first two examples.

Can MD5 be null?

The value of function MD5(col1) will be NULL if the value of col1 is NULL. However, if MD5 is used along with other NON NULL values, it will ignore the NULL value input and will return hash value of NON NULL input arguments.

What is MD5 () function?

What is MD5? MD5 (message-digest algorithm) is a cryptographic protocol used for authenticating messages as well as content verification and digital signatures. MD5 is based on a hash function that verifies that a file you sent matches the file received by the person you sent it to.


1 Answers

Prior to MySQL v5.5.3, MD5() returned a binary string.

By default, MySQL Workbench does not display binary strings (to avoid accidental misinterpretation); however it is possible to display binary string values in output grids: View > Edit > Preferences > SQL Editor > Treat BINARY/VARBINARY as nonbinary character string.

Alternatively, either upgrade your MySQL server or transcode the result to a non-binary character set:

SELECT CONVERT(MD5('test') USING utf8)
like image 153
eggyal Avatar answered Sep 28 '22 06:09

eggyal