Search code examples
mysqlipv6ipv4

Update MySQL new IPv6 column with existing IPv4 column data


I have the following two columns in a MySQL database table named "ip_test":

  • ipv4 as INT(11) (example value for 127.0.0.1: 2130706433).
  • ipv6 as VARBINARY (example value for 127.0.0.1: 0xFE800000000000000202B3FFFE1E8329).

What is the simplest manner to effectively convert the data (for a visual demonstration of the idea: UPDATE ip_test SET ipv6=ipv4;) though properly?


Solution

  • My goal was to avoid any server side scripting and to achieve this purely in MySQL. This seems correct from my initial tests:

    UPDATE ip_test SET ipv6 = INET6_ATON(INET_NTOA(ipv4));