MySQL 上的 MD5(RAND()) 仅返回数字

发布于 2024-09-18 09:58:48 字数 617 浏览 2 评论 0原文

我正在运行在谷歌搜索时找到的示例代码:

SELECT MD5(RAND())

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

我做错了什么吗?

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

编辑:我的MySQL版本:

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

MD5值示例:

6338666264663132376461666163313063656535633666616266396530613335

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

B9

这个字符串通常是个位数,到目前为止我得到的最长的是5位数字。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角迷惘 2024-09-25 09:58:48

没关系,我已经弄清楚了。

不知何故,phpMyAdmin 正在以二进制形式读取结果。
似乎有一个默认选中的选项“将二进制内容显示为十六进制”。

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

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.

分開簡單 2024-09-25 09:58:48

MySQL 文档确实建议结果应该是字符串或 NULL 无论如何。猜测一下,这种情况是否会因为 MD5() 的参数是数字而发生?如果您使用 SELECT MD5(CONCAT(RAND(), '')) 会发生什么?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文