views:

90

answers:

2

I'm running this sample code I found while googling:

SELECT MD5(RAND())

But, to my surprise, MD5 is returning plain digits, instead of hexadecimal digits. Using CONV(MD5(RAND()), 10, 16) seems to solve my problem, but the MySQL documentation states that the MD5 function should return a string already in hexadecimal.

Am I doing something wrong?

EDIT2: This problem only appears to exist with phpMyAdmin, not the command-line version of MySQL.

EDIT: My MySQL version:

mysql --version
mysql  Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (x86_64) using readline 6.1

An example MD5 value:

6338666264663132376461666163313063656535633666616266396530613335

Also, CONV returns a very VERY short string, like:

B9

This string is often single-digit and the longest I got until now was 5 digits.

A: 

The MySQL documentation does suggest that the result should be a string or NULL no matter what. At a guess, could this be happening because the argument to MD5() is a number? What happens if you use SELECT MD5(CONCAT(RAND(), ''))?

Hammerite
Nothing changes with CONCAT.
luiscubal
I put the function calls in the wrong order, answer edited.
Hammerite
@Hammerite Again, phpMyAdmin shows in decimal. Command-line version returns correct result.
luiscubal
Oh, I didn't realise you were using phpMyAdmin. I thought you were just using the MySQL command line. I would tend towards thinking this is a phpMyAdmin issue rather than a MySQL issue. Perhaps phpMyAdmin is programmed to try and identify numbers stored as strings, and display them as numbers??
Hammerite
@Hammerite Counter-intuitively, the option "Show binary contents as HEX" is what screwed things up in phpMyAdmin.
luiscubal
A: 

Nevermind, I figured it out.

Somehow, phpMyAdmin is reading the result as binary. There seems to be an option "Show binary contents as HEX" that's checked by default.

It appears that this "show as hex" option is causing the problems. Unchecking it seems to solve it.

luiscubal