IP address stored in Mysql

Source: Internet
Author: User
This article describes how to optimize IP fields in mysql data tables. Create a test table mysqlcreatetablehosts (

This article describes how to optimize IP fields in mysql data tables. Create a test table mysql create table hosts (-'id' int (8) not null auto_increment,-'IP' int unsigned not null,-'hostname' varchar (30) not null, -'desc' varchar (100),-primary key ('id') ENGINE = InnoDB; Q

This article describes how to optimize IP fields in mysql data tables.

Create test table

mysql> create table hosts(  -> `id` int(8) not null auto_increment, -> `ip` int unsigned not null, -> `hostname` varchar(30) not null, -> `desc` varchar(100) ,  -> PRIMARY KEY(`id`)) ENGINE=InnoDB;Query OK, 0 rows affected (0.03 sec)

View table structure

mysql> desc hosts -> ;+----------+------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------+------------------+------+-----+---------+----------------+| id | int(8) | NO | PRI | NULL | auto_increment || ip | int(10) unsigned | NO | | NULL | || hostname | varchar(30) | NO | | NULL | || desc | varchar(100) | YES | | NULL | |+----------+------------------+------+-----+---------+----------------+4 rows in set (0.00 sec)

Insert Test Data

mysql> insert into hosts (`ip`,`hostname`,`desc`) values (inet_aton('192.168.1.106'),'test','this is test host.');Query OK, 1 row affected (0.03 sec)
mysql> select * from hosts -> ;+----+------------+----------+--------------------+| id | ip | hostname | desc |+----+------------+----------+--------------------+| 1 | 3232235882 | test | this is test host. |+----+------------+----------+--------------------+1 row in set (0.00 sec)

Query

mysql> select inet_ntoa(ip) from hosts;+---------------+| inet_ntoa(ip) |+---------------+| 192.168.1.106 |+---------------+1 row in set (0.00 sec)

Original address: the IP address stored in Mysql. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.