So how many characters is enough to store an ip address in a mysql table? As the length of IP address varies from IPv4 to IPv6, To define the size of a column that ip address is going occupy, we must know maximum length of the ip address in both versions so that we can assign the maximum length to mysql column.

IPv4 addresses will be similar to the one given below,
125.222.168.110

From the above sample we can identify IPv4 addresses will consists 4 sets of 3 numbers, each set is separated by a dot(.). So this makes the length to be 15 characters (12+3).

IPv6 addresses will be similar to this one,
2001:0db8:85a3:0000:0000:8a2e:0370:7334

IPv6 addresses will consists of 8 sets of 4 characters, each separated by a colon(:). So this makes the length to be 39 characters(32+7).

Solution:
As IPv6 holds more number of characters(39), To store an ipaddress we need to have a column that holds 39 characters which is the maximum length of an ip address.

 


Comments (0)
Leave a Comment

loader Posting your comment...