优点:简单缺点:您需要更多的空间磁盘(〜+ 100%)缺点:您可能会存储无效的non hexa数据 BINARY(20):优点:减少磁盘空间优点:您不能存储无效数据缺点:您需要转换(如果需要,请参见hexa值)对我来说数据一致性是最重要的一点:我更喜欢二进制选项. unhex('FF')== unhex('ff')但'FF'<>'ff'尝试存储unhex('zz')会引发错误,文本不会引发错误而且Hex/unHex是非常简单的功能 提示:您可以将数据存储在BINARY列中,并创建一个hexa视图以轻松查看六边值.这里是在二进制区域 http://rextester.com/SEV11235 中存储数据的示例>I'm using the Ethereum api. I want to store the information from the api into a mysql table.The address data looks like:0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be0x1d80982502f3bb75654df13aa32bbd5ac9cab7d60xaf13bbdbe1ff53c2df7109a53c217320d2d76ee2...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 :CHAR(40) : (charset is not important here)pros : simplicitycons : you need more space disk (~+100%)cons : you risk to store invalid non hexa dataBINARY(20) :pros : reduce space diskpros : you can't store invalid datacons: you need to convert (if you need see hexa value)For me data consistency is the most important point : I prefer binary option.unhex('FF') == unhex('ff') but 'FF' <> 'ff'trying to store unhex('zz') raises an error, with text no error raised)Moreover Hex/unHex are very simple functionHint : You can store your data in BINARY column and create an hexa view to see easily hexa value.Here is an example to store data in binary zone http://rextester.com/SEV11235 这篇关于在数据库中存储十六进制和十六进制字符的最佳数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-16 17:44
查看更多