MySQL上的MD5(RAND())只返回数字 [英] MD5(RAND()) on MySQL returning only digits

查看:460
本文介绍了MySQL上的MD5(RAND())只返回数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SELECT MD5(RAND())

但令我惊讶的是,MD5返回的是纯数字,而不是十六进制数字。
使用 CONV(MD5(RAND()),10,16)似乎解决了我的问题,但MySQL文档声明MD5函数应该返回一个字符串已经在十六进制。



我做错了什么?



编辑2:这个问题似乎只存在于phpMyAdmin ,而不是命令行版本的MySQL。



编辑:我的MySQL版本:

  mysql --version 
mysql Ver 14.14 Distrib 5.1.41,用于使用readline的debian-linux-gnu(x86_64)6.1

示例MD5值:

  6338666264663132376461666163313063656535633666616266396530613335 

另外,CONV会返回一个非常短的字符串,例如:

  B9 

这个字符串通常是单位数字,现在是5位数字。

解决方案

没关系,我想明白了。

不知何故, phpMyAdmin以二进制形式读取结果。
似乎有一个选项显示二进制内容为HEX,这是默认选中的。



看起来这个显示为十六进制选项导致问题。取消它似乎解决了它。


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.

解决方案

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.

这篇关于MySQL上的MD5(RAND())只返回数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆