5

I don't know enough about the function, or ip's, to determine how my column structure should be for storing this. Any suggestions?

soren.qvist
  • 7,376
  • 14
  • 62
  • 91
  • IPv4 is a 4 byte address, so that fits perfectly into an unsigned INT. (That's what `long` in `ip2long` is.) IPv6 addresses won't fit in 4 bytes though =) You'll need 16 bytes. – Rudie Apr 30 '11 at 13:47

2 Answers2

5

Simply use an unsigned INT field for it.

Also see http://lists.mysql.com/cluster/2781 for a discussion about it.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
4

Using INT is fine when you're dealing with IPv4 addresses. However 128-bits long IPv6 can't be stored as INT or even BIGINT.

  1. How to store IPv6-compatible address in a relational database
  2. How to convert IPv6 from binary for storage in MySQL
  3. http://www.google.com/search?client=opera&rls=en&q=storing+ipv6+mysql&sourceid=opera&ie=utf-8&oe=utf-8
Community
  • 1
  • 1
Crozin
  • 43,890
  • 13
  • 88
  • 135