mysql inet aton ipv6_mysql – 存储IPv4和IPv6主机和网络

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

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.

我也知道以下问题“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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值