Reputation: 2564
INET_ATON()
Return the numeric value of an IP address
INET6_ATON()
Return the numeric value of an IPv6 address
i have a column contain ipv4 & ipv6 both.
I try to convert those to number 'ip_long'(column's name)
I use INET_ATON,
it only convert ipv4
My question is, does INET6_ATON
convert ipv6 only or both?
Is any function can convert both? I have million rows in db need to convert.
Upvotes: 2
Views: 4037
Reputation: 1064
INET6_ATON()
will convert both ipv4 and ipv6. As you already know, you need MySQL version 5.6.x or higher.
The catch is to use only INET6_ATON()
and INET6_NTOA()
. The column which will store the the converted IPs will be of VARBINARY(16)
type.
SELECT INET6_NTOA(INET6_ATON("192.168.1.1"));
SELECT INET6_NTOA(INET6_ATON("2001:db8::1"));
Remember that the ip
column from test_table is VARBINARY(16);
Upvotes: 4