MySQL IS_IPV4_COMPAT() Function

In MySQL, the IS_IPV4_COMPAT() function checks whether a numeric IPv6 address is an IPv4-compatible IPv6 address.

IS_IPV4_COMPAT() Syntax

Here is the syntax of the MySQL IS_IPV4_COMPAT() function:

IS_IPV4_COMPAT(ip)

Parameters

ip
Required. An IPv6 address to check.

Return value

The MySQL IS_IPV4_COMPAT() function checks whether a numeric IPv6 address is an IPv4-compatible IPv6 address, and returns 1 if it is, otherwise returns 0.

If the argument is NULL, the function will return NULL.

IS_IPV4_COMPAT() Examples

This example demonstrates the basic usage of IS_IPV4_COMPAT().

SELECT
    IS_IPV4_COMPAT(INET6_ATON('::192.168.1.100')),
    IS_IPV4_COMPAT(INET6_ATON('::ffff:192.168.1.100'));
+-----------------------------------------------+----------------------------------------------------+
| IS_IPV4_COMPAT(INET6_ATON('::192.168.1.100')) | IS_IPV4_COMPAT(INET6_ATON('::ffff:192.168.1.100')) |
+-----------------------------------------------+----------------------------------------------------+
|                                             1 |                                                  0 |
+-----------------------------------------------+----------------------------------------------------+

Here, since ::ffff:192.168.1.100 is not an IPv4-compatible IPv6 address, IS_IPV4_COMPAT(INET6_ATON('::ffff:192.168.1.100')) returned 0.