what should be the ideal size for storing IPv4, IPv6 addresses as a string in the MySQL database. should varchar(32) be sufficient?
See Question&Answers more detail:oswhat should be the ideal size for storing IPv4, IPv6 addresses as a string in the MySQL database. should varchar(32) be sufficient?
See Question&Answers more detail:osAssuming textual representation in a string :
xxx.xxx.xxx.xxx
format, 12+3
separators)Those are the maximum length of the string.
Alternatives to storing as string:
INT UNSIGNED
is common along with INET_ATON
and INET_NTOA
to handle the conversion from address to number, and from number to addressSELECT INET_ATON('209.207.224.40'); -> 3520061480 SELECT INET_NTOA(3520061480); -> '209.207.224.40'
BIGINT
(8 bytes), this however will use two fields.