How to match an ip address in mysql?

后端 未结 5 987
無奈伤痛
無奈伤痛 2021-01-04 23:15

For example, I am having a column storing data like this.

Apple
12.5.126.40
Smite
Abby
127.0.0.1
56.5.4.8
9876543210
Notes

How to select ou

5条回答
  •  没有蜡笔的小新
    2021-01-04 23:51

    IS_IPV4() is a native mysql function that lets you check whether a value is a valid IP Version 4.

    SELECT *
    FROM ip_containing_table
    WHERE IS_IPV4(ip_containing_column);
    

    I don't have data, but I reckon that this must be the most solid and efficient way to do this.

    There are also similar native functions that check for IP Version 6 etc.

提交回复
热议问题