dsv768456 2013-09-29 14:08
浏览 56
已采纳

为什么mysql HEX会改变二进制列的情况?

The following query changes the case of the md5 column from lower to upper. The MD5 value was provided via PHP's md5() function, and I am using it in a HTML link to send $_GET data to the server. Why does the case change? Is one case more proper than the other? I understand I can deal with it using LOWER().

http://sqlfiddle.com/#!2/414c8/1

CREATE TABLE myTable (
  id INT NOT NULL AUTO_INCREMENT,md5 BINARY(16),
  PRIMARY KEY (id) )
ENGINE = InnoDB;

INSERT INTO myTable(md5)VALUES(UNHEX("06fcf5b90b916bdc533e2badec396b90"));

SELECT id,HEX(md5) FROM myTable;

ID  HEX(MD5)
1   06FCF5B90B916BDC533E2BADEC396B90
  • 写回答

2条回答 默认 最新

  • dsc7188 2013-09-29 14:15
    关注

    It doesn't change case. HEX() just returns the uppercase letters. The way the value is stored has no letters in it at all - it's the actual binary representation. There is no way to preserve the "case" in that column.

    You can always make the column wider and store the text itself (without HEX/UNHEX) if you don't want to do the conversion later.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制