MySQL Forums
Forum List  »  MyISAM

Re: Best Field Type for IP address?
Posted by: Me Me
Date: May 18, 2006 01:23PM

Hi,

You could indeed store the IP addres in an INT UNSIGNED:

mysql> SELECT INET_ATON('192.168.0.10') AS ipn;
+------------+
| ipn |
+------------+
| 3232235530 |
+------------+

mysql> SELECT INET_NTOA(3232235530) AS ipa;
+--------------+
| ipa |
+--------------+
| 192.168.0.10 |
+--------------+

So you can store an IP address in an INT UNSIGNED (4 bytes) which is of course much more efficient and faster than a CHAR(15). Naturally, you can call the function while you're inserting, so something like this is fine also:

INSERT INTO tbl VALUES (..., INET_ATON('192.168.0.10'), ...)

Best Regards,

Dave Laurier

Options: ReplyQuote


Subject
Views
Written By
Posted
44820
October 12, 2005 12:19PM
26077
October 17, 2005 01:37PM
Re: Best Field Type for IP address?
39959
May 18, 2006 01:23PM
14505
October 02, 2006 09:34AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.