MySQL存储IP地址的方法

52 阅读1分钟

 IP转数字函数inet_aton()

 

mysql> ``select``inet_aton(``'192.168.1.1'``); 

+``--------------------------+

| inet_aton(``'192.168.1.1'``) |

+``--------------------------+

|        3232235777 |

+``--------------------------+

1 row ``in``set``(0.00 sec)

 

 

 

数字转IP函数inet_ntoa()

 

 

mysql> ``select``inet_ntoa(3232235777);

+``-----------------------+

| inet_ntoa(3232235777) |

+``-----------------------+

| 192.168.1.1      |

+``-----------------------+

1 row ``in``set``(0.00 sec)