ItSolutionStuff.com

Which MySQL Datatype use for Store an IP Address?

By Hardik Savani β€’ January 6, 2023
PHP MySql

If you want to store IP address in mysql database then don’t mistake to use varchar datatype because you can use INT UNSIGNED 4(BYTE) datatype. using integer datatype you can save more space in database.

when you fire insert query at that time use INET_ATON() and select query at that time INET_NTOA() use. how to use this function given bellow example.

Create Table :

CREATE TABLE IF NOT EXISTS `ip_addresses` (

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

`ip_address` INT(4) UNSIGNED NOT NULL,

PRIMARY KEY (`id`)

);

Insert Data :

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

Select Data :

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

Try this, this is a very simple.......

Tags: MySql
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

PHP MySQL Column Sorting Example Tutorial

Read Now β†’
β˜…

PHP MySQL Image Gallery CRUD Example

Read Now β†’
β˜…

PHP MySQL Highcharts Chart Example

Read Now β†’
β˜…

How to Get Filename from File Path in MySQL Query?

Read Now β†’
β˜…

How to Get IP Address in Codeigniter?

Read Now β†’
β˜…

How to Get IP Address in JQuery?

Read Now β†’
β˜…

How to Get User IP Address in PHP?

Read Now β†’
β˜…

How to Execute MySQL Query in Laravel?

Read Now β†’
β˜…

How to Get IP Address in Laravel?

Read Now β†’
β˜…

Mysql Hexadecimal Color Code Store in Binary Datatype Example

Read Now β†’