MD5(RAND()) on MySQL returning only digits

只愿长相守 提交于 2019-12-23 13:21:23

问题


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.


回答1:


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.




回答2:


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(), ''))?



来源:https://stackoverflow.com/questions/3685534/md5rand-on-mysql-returning-only-digits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!