Store the ip as a INT(11) UNSIGNED
, then use the INET_ATON
and INET_NTOA
functions to store/retrieve the ip address.
Sample code:
INSERT table(ip) VALUES (INET_ATON('192.168.0.1')); /*ip = 3232235521*/
SELECT INET_NTOA(ip) As IPAddress FROM table; /*IPAddress = 192.168.0.1*/