Use the built-in functions of mysql:
INET_ATON (expr)
Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric value of the address. Addresses may be 4-or 8-byte addresses.
Mysql> SELECT INET_ATON ('2017. 207.224.40 ');
-> 3520061480
The generated number is always in network byte order. For the example just shown, the number is calculated as 209 × 2563 + 207 × 2562 + 224 × 256 + 40.
INET_ATON () also understands short-formIPaddresses:
Mysql> SELECT INET_ATON ('2014. 0.0.1 '), INET_ATON ('2014. 1 ');
-> 2130706433,213 0706433
Note: When storing values generated by INET_ATON (), it is recommended that you use an int unsigned column. if you use a (signed) INT column, values corresponding toIPaddresses for which the first octet is greater than 127 cannot be stored correctly. see Section 11.2, "Numeric Types ".
INET_NTOA (expr)
Given a numeric network address (4 or 8 byte), returns the dotted-quad representation of the address as a string.
Mysql> SELECT INET_NTOA (3520061480 );
-> '2014. 207.224.40'
The above is the description in the Mysql Manual. The actual usage is as follows:
My ip address is stored as a string in the ip_info field of table table_ip. You can use the following query statement to return the results sorted by ip address.
Select ip_info from table_ip order by inet_aton (ip_info );
Result:
192.168.6.10
192.168.6.60
92.166.120
92.166.240
...
Recommended reading:
MySQL execution plan changes as the data volume increases
Login in MySQL database security mode