Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the ideal datatype to store IP address in a mysql table? [duplicate]

Tags:

sql

mysql

Possible Duplicate:
What type should I store IP addresses for MySQL?

One single datatype which can accommodate both IPv4 and IPv6 addresses. I want to store IP addresses to limit the number of profiles that a person can make from his/her machine in my website.

like image 280
Robbie Dc Avatar asked Nov 16 '11 19:11

Robbie Dc


People also ask

What data type use for IP address in MySQL?

MySQL. While MySQL doesn't have a data type for IP addresses, it's still easy to compare IPs in MySQL. Using inet_aton you can convert your IP addresses to integers before you compare.

What datatype is an IP address?

IP Network Address Data Types. IPV4 and IPV6 are abstract data types that store IPv4 and IPv6 host addresses, respectively, in binary format. IPV4 is a 4-byte host address in dotted-decimal notation (four decimal numbers, each ranging from 0 to 255, separated by dots). For example: 172.16.

Which data type you choose if store address in database?

Varchar will be used as data type for address in sql as it supports both characters and numbers and special characters.

How do I find my IP address in MySQL?

The SQL query SHOW VARIABLES WHERE Variable_name = 'hostname' will show you the hostname of the MySQL server which you can easily resolve to its IP address. SHOW VARIABLES WHERE Variable_name = 'port' Will give you the port number.


1 Answers

IPv4 addresses use 32 bits (4 bytes), IPv6 addresses use 128 bits (16 bytes). Thus, you can store their binary representation in BINARY(16) or VARBINARY(16) fields.

Also see my answer to the question IP address storing in mysql database. It also provides comments why you would choose one over the other.

like image 67
knittl Avatar answered Nov 15 '22 15:11

knittl