在mysql表中存储IP地址的理想数据类型是什么? [英] What is the ideal datatype to store IP address in a mysql table?

查看:323
本文介绍了在mysql表中存储IP地址的理想数据类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
我应该为MySQL存储哪种类型的IP地址?

Possible Duplicate:
What type should I store IP addresses for MySQL?

可以容纳IPv4和IPv6地址的单个数据类型.我想存储IP地址以限制一个人可以在我的网站上通过他/她的机器进行配置的数量.

One single datatype which can accommodate both IPv4 and IPv6 addresses. I want to store IP addresses to limit the number of profiles that a person can make from his/her machine in my website.

推荐答案

IPv4地址使用32位(4字节),IPv6地址使用128位(16字节).因此,您可以将它们的二进制表示形式存储在BINARY(16)VARBINARY(16)字段中.

IPv4 addresses use 32 bits (4 bytes), IPv6 addresses use 128 bits (16 bytes). Thus, you can store their binary representation in BINARY(16) or VARBINARY(16) fields.

另请参阅我对问题的回答存储在mysql数据库中的IP地址.它还提供注释,说明为什么您会选择一个.

Also see my answer to the question IP address storing in mysql database. It also provides comments why you would choose one over the other.

这篇关于在mysql表中存储IP地址的理想数据类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆