Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest VARBINARY for storing IP addresses #13

Open
macbre opened this issue Oct 22, 2017 · 0 comments
Open

Suggest VARBINARY for storing IP addresses #13

macbre opened this issue Oct 22, 2017 · 0 comments

Comments

@macbre
Copy link
Owner

macbre commented Oct 22, 2017

  • 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

@macbre macbre changed the title Suggest varbinary(16) for storing IP addresses Suggest VARBINARY for storing IP addresses Oct 22, 2017
@macbre macbre added the linters label Nov 20, 2017
@macbre macbre added this to the v1.2 milestone Feb 19, 2018
@macbre macbre removed this from the v1.2 milestone Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant