Skip to content

Suggest VARBINARY for storing IP addresses #13

@macbre

Description

@macbre
  • check text columns if they contain IP addresses
  • suggest varbinary(16) for storing IPv4/v6 addresses

https://www.designcise.com/web/tutorial/whats-the-best-way-to-store-an-ip-address-in-mysql

To optimize the storage of an IP address (v4 or v6) in a MySQL database consider using VARBINARY data type for the ip storage field as it uses less storage space by storing byte strings rather than character strings. In this article we look at ways to convert a string IP address into its corresponding binary representation that is database storage-ready.

INSERT INTO user_ip (ip) VALUES (INET6_ATON('127.0.0.1'))
SELECT * FROM user_ip WHERE ip = INET6_ATON('127.0.0.1')

The string types are CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM, and SET.

https://dev.mysql.com/doc/refman/5.7/en/string-types.html

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions