如何在关系数据库中存储兼容 IPv6 的地址

How to store IPv6-compatible address in a relational database(如何在关系数据库中存储兼容 IPv6 的地址)
本文介绍了如何在关系数据库中存储兼容 IPv6 的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我该怎么做?

目前不会使用 IPv6,但我需要设计应用程序以使其支持 IPv6.有必要在 MySQL 数据库中存储 IP 地址和 CIDR 块(也是 BGP NLRI,但这是另一回事).我一直对 IPv4 使用 INT + 对 masklen 使用 TINYINT,但 IPv6 是 128 位.

Right now, IPv6 will not be used, but I need to design the application to make it IPv6-ready. It is necessary to store IP addresses and CIDR blocks (also BGP NLRI, but this is another story) in a MySQL database. I've alway used an INT for IPv4 + a TINYINT for masklen, but IPv6 is 128 bit.

什么方法最适合这种情况?2xBIGINT?CHAR(16) 用于二进制存储?CHAR(39) 用于文本存储?8xSMALLINT 在专用表中?

What approach will be best for that? 2xBIGINT? CHAR(16) for binary storage? CHAR(39) for text storage? 8xSMALLINT in a dedicated table?

你会推荐什么?

推荐答案

我不确定哪个是 MySQL 的正确答案,因为它本身还不支持 IPv6 地址格式(尽管而WL#798: MySQL IPv6 support"表明它正在运行在 MySQL v6.0 中,当前文档不支持.

I'm not sure which is the right answer for MySQL given that it doesn't yet support IPv6 address formats natively (although whilst "WL#798: MySQL IPv6 support" suggests that it was going to be in MySQL v6.0, current documentation doesn't back that up).

但是,在您提出的那些中,我建议使用 2 * BIGINT,但请确保它们是未签名的.在 IPv6 中的/64 地址边界处有一种自然分割(因为/64 是最小的网络块大小),这将很好地与此对齐.

However of those you've proposed I'd suggest going for 2 * BIGINT, but make sure they're UNSIGNED. There's a sort of a natural split at the /64 address boundary in IPv6 (since a /64 is the smallest netblock size) which would align nicely with that.

这篇关于如何在关系数据库中存储兼容 IPv6 的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)