mysql>
mysql> CREATE TABLE hostip
-> (
-> ip VARCHAR(64)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> INSERT INTO hostip (ip)
-> VALUES
-> ('127.0.0.1'),
-> ('192.168.0.2'),
-> ('192.168.0.10'),
-> ('192.168.1.2'),
-> ('192.168.1.10'),
-> ('255.255.255.255'),
-> ('21.0.0.1')
-> ;
Query OK, 7 rows affected (0.00 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql>
mysql> SELECT ip FROM hostip
-> ORDER BY
-> SUBSTRING_INDEX(ip,'.',1)+0,
-> SUBSTRING_INDEX(SUBSTRING_INDEX(ip,'.',-3),'.',1)+0,
-> SUBSTRING_INDEX(SUBSTRING_INDEX(ip,'.',-2),'.',1)+0,
-> SUBSTRING_INDEX(ip,'.',-1)+0;
+-----------------+
| ip |
+-----------------+
| 21.0.0.1 |
| 127.0.0.1 |
| 192.168.0.2 |
| 192.168.0.10 |
| 192.168.1.2 |
| 192.168.1.10 |
| 255.255.255.255 |
+-----------------+
7 rows in set (0.00 sec)
mysql>
mysql> drop table hostip;
Query OK, 0 rows affected (0.00 sec)