Storing IP address in MySQL database (IPv4 AND IPv6)

前端 未结 5 2328
时光取名叫无心
时光取名叫无心 2021-02-15 17:54

Ok, now I\'m aware that similar questions have probably been asked a million times but I\'m a real novice at this and I\'d really appreciate your help here.

Basically, I

5条回答
  •  悲哀的现实
    2021-02-15 18:49

    There is no integral type in MySQL big enough to store an IPv6 address. The most compact way to store it is as something like BINARY(16). If you just need to store and retrieve addresses and you don't need to perform logical operations on them (e.g. netmask operations to query for which IP addresses come under a covering prefix) then that will be enough. If you need to do logical or bit operations, you will need to be fancier: you will need to store IPv6 addresses in two separate 64-bit integer columns.

提交回复
热议问题