Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 我应该如何构造一个数据库来存储大量SHA1数据_Mysql - Fatal编程技术网

Mysql 我应该如何构造一个数据库来存储大量SHA1数据

Mysql 我应该如何构造一个数据库来存储大量SHA1数据,mysql,Mysql,我在构建数据库以存储大量SHA1数据和高效返回结果时遇到了问题 我承认SQL并不是我最强的技能,但作为一种练习,我正在尝试使用能够快速返回结果的数据 这是我的数据: mysql> describe pwnd; +----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra

我在构建数据库以存储大量SHA1数据和高效返回结果时遇到了问题

我承认SQL并不是我最强的技能,但作为一种练习,我正在尝试使用能够快速返回结果的数据

这是我的数据:

mysql> describe pwnd;
+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| id       | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| pwndpass | binary(20)       | NO   |     | NULL    |                |
+----------+------------------+------+-----+---------+----------------+

mysql> select id, hex(pwndpass) from pwnd order by id desc limit 10;
+-----------+------------------------------------------+
| id        | hex(pwndpass)                            |
+-----------+------------------------------------------+
| 306259512 | FFFFFFFEE791CBAC0F6305CAF0CEE06BBE131160 |
| 306259511 | FFFFFFF8A0382AA9C8D9536EFBA77F261815334D |
| 306259510 | FFFFFFF1A63ACC70BEA924C5DBABEE4B9B18C82D |
| 306259509 | FFFFFFE3C3C05FCB0B211FD0C23404F75E397E8F |
| 306259508 | FFFFFFD691D669D3364161E05538A6E81E80B7A3 |
| 306259507 | FFFFFFCC6BD39537AB7398B59CEC917C66A496EB |
| 306259506 | FFFFFFBFAD0B653BDAC698485C6D105F3C3682B2 |
| 306259505 | FFFFFFBBFC923A29A3B4931B63684CAAE48EAC4F |
| 306259504 | FFFFFFB58E389A0FB9A27D153798956187B1B786 |
| 306259503 | FFFFFFB54953F45EA030FF13619B930C96A9C0E3 |
+-----------+------------------------------------------+
10 rows in set (0.01 sec)
我的问题与快速查找条目有关,因为它目前需要6分钟以上的时间

mysql> select hex(pwndpass) from pwnd where hex(pwndpass) = '0000000A1D4B746FAA3FD526FF6D5BC8052FDB38';
+------------------------------------------+
| hex(pwndpass)                            |
+------------------------------------------+
| 0000000A1D4B746FAA3FD526FF6D5BC8052FDB38 |
+------------------------------------------+
1 row in set (6 min 31.82 sec)
我有正确的数据类型吗?我搜索存储sha1数据,建议使用二进制(20)字段,但不确定如何优化该字段以搜索数据


我的MySQL安装是一个干净的交钥匙虚拟机,除了给虚拟机更多的磁盘空间之外,我没有调整任何设置

  • 在列上创建索引
  • 不要在每次搜索时将每一行转换为十六进制:

    select hex(pwndpass)
    from pwnd
    where hex(pwndpass) = '0000000A1D4B746FAA3FD526FF6D5BC8052FDB38';
    --    ^^^ This is forcing MySQL to convert every hash stored from binary to hexadecimal
    --        so it can determine whether there's a match
    
事实上,您甚至不需要十六进制,保存用于显示:

select id, hex(pwndpass) -- This is fine, will just convert matching rows
from pwnd
where pwndpass = ?
。。。其中,
是一个占位符,在客户端语言中,它对应于一个二进制字符串

如果需要在命令行中直接运行查询,还可以使用:


创建一个索引怎么样?你能给我指出正确的方向吗?快速谷歌,我有一些东西要读。谢谢你能详细介绍一下我应该如何做SELECT声明吗?我已经玩了好几天,努力想得到结果谢谢你的精彩解释,你的解决方案非常有效
select id, hex(pwndpass) -- This is fine, will just convert matching rows
from pwnd
where pwndpass = 0x0000000A1D4B746FAA3FD526FF6D5BC8052FDB38