利用mysql的inet_aton()和inet_ntoa()函数存储IP地址

来源:互联网 发布:算法之道 结构之法pdf 编辑:程序博客网 时间:2024/05/17 23:19

mysql> create table jackbillow (ip int unsigned, name char(1));
Query OK, 0 rows affected (0.02 sec)

 

mysql> insert into jackbillow values(inet_aton('192.168.1.200'), 'A'), (inet_aton('200.100.30.241'), 'B');                         
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

 

mysql> insert into jackbillow values(inet_aton('24.89.35.27'), 'C'), (inet_aton('100.200.30.22'), 'D');                            
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from jackbillow;
+------------+------+
| ip         | name |
+------------+------+
| 3232235976 | A    |
| 3362004721 | B    |
|  408494875 | C    |
| 1690836502 | D    |
+------------+------+
4 rows in set (0.00 sec)