在数据库表中存储IP地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在数据库表中存储IP地址相关的知识,希望对你有一定的参考价值。
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).mysql has two built-in functions: INET_ATON() and INET_NTOA(). These two functions are used allover the place in any TCP/IP stack implementation or even application.
The INET_ATON() function converts Internet addresses from the numbers-and-dots notation into a 32-bit unsigned integer, and INET_NTOA() does the opposite.
SELECT INET_ATON('192.168.0.10') AS ipn; SELECT INET_NTOA(3232235530) AS ipa; INSERT INTO tbl VALUES (..., INET_ATON('192.168.0.10'), ...);
以上是关于在数据库表中存储IP地址的主要内容,如果未能解决你的问题,请参考以下文章