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