If you want to store an IP address in mysql database do not hesitate to use varchar datatype because you can use INT UNSIGNED 4 (BYTE) datatype. using a complete database, you can save more space in the database.

If you enter a question then use INET_ATON () and then select the question immediately using INET_NTOA (). how you can use this function given a clear example.

Step 1 : Create Table

CREATE TABLE IF NOT EXISTS `ip_addresses_table` (

  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `ip_address` INT(4) UNSIGNED NOT NULL,

  PRIMARY KEY (`id`)

);

Step 2 : Insert Data

INSERT INTO `ip_addresses_table` (`ip_address`) VALUES (INET_ATON("127.0.0.1"));

Step 3: Select Data

SELECT id, INET_NTOA(`ip_address`) as ip FROM `ip_addresses_table`;