MySQL
Store IPv4 and IPv6 Together in MySQL With INET6_ATON()
One column for both address families: INET6_ATON() and INET6_NTOA(), IPv4-mapped addresses, correct sorting, indexed range queries and MariaDB's native INET6 type.
Category
MySQL and MariaDB: stored functions, queries, data types and practical database notes.
One column for both address families: INET6_ATON() and INET6_NTOA(), IPv4-mapped addresses, correct sorting, indexed range queries and MariaDB's native INET6 type.
Store IPv4 addresses as INT UNSIGNED and test CIDR membership with a bitmask or, much faster on a big table, an indexed BETWEEN range on network and broadcast.
Work out the network, broadcast address and prefix length of an IPv4 address inside a query, using INET_ATON(), INET_NTOA() and a little bitwise arithmetic.