MySQL optimized storage for IP addresses

Source: Internet
Author: User
Tags ip number

Why optimize the storage of IP addresses?

Many times, when we operate MySQL, and to be overly concerned about how to optimize the content of MySQL storage, improve access speed, but do any program design on the basis of functional implementation to maximize performance optimization. The database design is an important part of the programming, reasonable use of certain optimization methods, prove that you get rid of the entry-level novice title.

The IP Type field is not directly available in MySQL, but there are two functions that can transfer IP with a maximum length of 10-bit numeric type, so using an int type storage IP is much better than the varchar type storage IP address performance, reducing a lot of space. Because varchar is a variable-length shape, extra bytes are required to store the length. In addition, the int type is faster than the varchar speed in the logical operation.

IP to numeric function Inet_aton () Digital to IP function Inet_ntoa ()

The field of the IP table can be set to int (10), if the IP is not obtained can be directly stored 0 means not to get the IP meaning,

0 Convert IP Rep 0.0.0.0

The comparison of integer fields is much more efficient than string, which also conforms to an optimization principle: The field type definition uses the most appropriate (minimum) and simplest data type.
The Inet_aton () algorithm, in fact, borrows the IP number used in the international distinction of IP addresses of countries.
The IP number of the A.B.C.D is:
A * 256 of 3 parties + b * 256 2 times Square + c * 256 1 Times Square + D * 256 0.

MySQL optimized storage for IP addresses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.