mysql 存16进制数据类型,在数据库中存储十六进制和十六进制字符的最佳数据类型...

在存储Ethereum API获取的地址数据时,原始的varchar列被使用。考虑到数据一致性,文章讨论了使用varbinary和BINARY数据类型的优缺点。varbinary可以节省空间并防止非十六进制数据的存储,但需要转换。BINARY(20)提供数据校验,但显示为十六进制时需额外处理。建议采用BINARY结合创建hexa视图以兼顾存储和查看需求。
摘要由CSDN通过智能技术生成

I'm using the Ethereum api. I want to store the information from the api into a mysql table.

The address data looks like:

0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be

0x1d80982502f3bb75654df13aa32bbd5ac9cab7d6

0xaf13bbdbe1ff53c2df7109a53c217320d2d76ee2

...

I've been using just varchar column for these characters. Are there a better data type? I'm thinking maybe varbinary but I don't know if there's any advantages. The disadvantage is that the sql code will be messier as I will have to HEX() and UNHEX().

解决方案

For me no specific type exists, you need to choose between text and binary :

pros : simplicity

cons : you need more space disk (~+100%)

cons : you risk to store invalid non hexa data

BINARY(20) :

pros : reduce space disk

pros : you can't store invalid d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值