在mysql表中存储IP地址的理想数据类型是什么? [重复]

时间:2022-01-23 18:02:58

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

可能重复:我应该为MySQL存储什么类型的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和IPv6地址。我想存储IP地址,以限制一个人可以在我的网站上使用他/她的机器制作的配置文件数量。

3 个解决方案

#1


7  

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.

IPv4地址使用32位(4字节),IPv6地址使用128位(16字节)。因此,您可以将其二进制表示存储在BINARY(16)或VARBINARY(16)字段中。

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地址问题的回答。它还提供注释,为什么你会选择一个而不是另一个。

#2


3  

You could use an UNSIGNED INT and use INET_ATON and INET_NTOA to encode and decode it.

您可以使用UNSIGNED INT并使用INET_ATON和INET_NTOA对其进行编码和解码。

#3


0  

A trie datatype would be optimal. There is uncompressed and compressed data struture from that type.

trie数据类型是最佳的。该类型存在未压缩和压缩的数据结构。

#1


7  

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.

IPv4地址使用32位(4字节),IPv6地址使用128位(16字节)。因此,您可以将其二进制表示存储在BINARY(16)或VARBINARY(16)字段中。

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地址问题的回答。它还提供注释,为什么你会选择一个而不是另一个。

#2


3  

You could use an UNSIGNED INT and use INET_ATON and INET_NTOA to encode and decode it.

您可以使用UNSIGNED INT并使用INET_ATON和INET_NTOA对其进行编码和解码。

#3


0  

A trie datatype would be optimal. There is uncompressed and compressed data struture from that type.

trie数据类型是最佳的。该类型存在未压缩和压缩的数据结构。