如何在不使用文本字段的情况下在MySQL数据库中存储散列 [英] How to store hashes in MySQL databases without using text fields

查看:176
本文介绍了如何在不使用文本字段的情况下在MySQL数据库中存储散列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将唯一的用户代理存储在MySQL MyISAM表中,因此当我必须查看它是否存在于表中时,我检查 md5 hash 存储在TEXT字段旁边。

 用户代理
{
id - INT
user-agent - TEXT
hash - VARCHAR(32)// md5
}



<有什么办法可以做到这一点,但使用32位整数,而不是文本哈希?原始格式的md5可能会更快?这将需要二进制搜索。



MySQL不处理完整大小的哈希搜索-sensitive strings?

解决方案

让MySQL为您做好工作。使用CHAR列和创建索引柱。您可以将散列转换并存储为整数,但绝对没有好处,并且可能会导致问题。


I'm storing unique user-agents in a MySQL MyISAM table so when I have to look if it exists in the table, I check the md5 hash that is stored next to the TEXT field.

User-Agents 
{
    id         - INT
    user-agent - TEXT
    hash       - VARCHAR(32) // md5
}

There is any way to do the same but using a 32-bit integer and not a text hash? Maybe the md5 in raw format will be faster? That will requiere a binary search.

[EDIT]

MySQL don't handle hash searches for complete case-sensitive strings?

解决方案

Let MySQL do the hard work for you. Use a CHAR column and create an index on that column. You could convert and store the hash as an integer, but there's absolutely no benefit, and it may actually cause problems.

这篇关于如何在不使用文本字段的情况下在MySQL数据库中存储散列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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