【问题标题】:Help out a beginner with MySQL docs byte definitions帮助初学者使用 MySQL 文档字节定义
【发布时间】:2011-02-15 15:54:09
【问题描述】:

http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-aton

我想将用户 IP 以数值形式存储在我的数据库中。文档对 INET_ATON 函数进行了以下说明:

将网络地址的点分四进制表示为字符串,返回一个表示地址数值的整数。 地址可以是 4 字节或 8 字节地址。

这到底是什么意思?我的 unsigned int 字段应该是什么长度来存储这些值?

感谢您的宝贵时间!

【问题讨论】:

    标签: mysql database documentation byte


    【解决方案1】:

    IPv4 使用 32 位(四字节)地址,
    这将地址空间限制为 4,294,967,296 (232)

    示例:

    create table ip ( ip int(10) unsigned default 0);
    insert into ip values ( inet_aton('255.255.255.255')), (inet_aton('0.0.0.0'));
    select * from ip;
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    相关资源
    最近更新 更多