ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

mysql – 存储IPv4和IPv6主机和网络

2019-08-06 11:13:54  阅读:561  来源: 互联网

标签:mysql database-design datatypes network


我必须将IPv4 / v6地址和网络(CIDR表示法)存储在MySQL数据库中.不幸的是,我被限制使用Mysql.

所以,我正在寻找相当于inet type of PostgreSql.

The inet type holds an IPv4 or IPv6 host address, and optionally its
subnet, all in one field
. The subnet is represented by the number of
network address bits present in the host address (the “netmask”). If
the netmask is 32 and the address is IPv4, then the value does not
indicate a subnet, only a single host. In IPv6, the address length is
128 bits, so 128 bits specify a unique host address.

The input format for this type is address/y where address is an IPv4
or IPv6 address and y is the number of bits in the netmask. If the /y
portion is missing, the netmask is 32 for IPv4 and 128 for IPv6, so
the value represents just a single host. On display, the /y portion is
suppressed if the netmask specifies a single host.

我知道Mysql 5.6 INET_ATON(), INET_NTOA(), INET6_ATON(), INET6_NTOA()的以下功能.但我使用的是Mysql 5.5 … So, forget INET6_xxxx.

我也知道以下问题“Storing IP address”,但它不涉及网络CIDR表示法.

如何在Mysql 5.5中实现等效的inet类型?

> 3列:网络(2xBIGINT),CIDR(TINYINT)?
>字符串? (@Phil)

解决方法:

第一:MySQL中没有相当于PostgreSql的inet类型.

您应该只使用字符串类型来存储所有类型的IP地址.
如果您需要以特定格式使用它们,请在将它们插入数据库之前进行转换.

如果你需要用它们进行计算,正如你提到的INET_ATON()和INET_NTOA()是需要使用的函数.

标签:mysql,database-design,datatypes,network
来源: https://codeday.me/bug/20190806/1598822.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有