2,187
edits
(→COUNT: Added GROUP BY example) |
(→IP Addresses: Elaborated a bit) |
||
Line 89: | Line 89: | ||
=== IP Addresses === | === IP Addresses === | ||
IP addresses are most efficiently stored as an UNSIGNED INT, though obviously this isn't particularly human readable. | IP addresses are most efficiently stored as an UNSIGNED INT, though obviously this isn't particularly human readable, but it is beneficial in as much as that if you use a <code> SELECT ... ORDER BY ip </code> type of statement the IP's will be correctly sorted | ||
MySQL will do the conversion between INT and dotted quad using the INET_ATON and INET_NTOA functions. For example; | MySQL will do the conversion between INT and dotted quad using the INET_ATON and INET_NTOA functions. For example; | ||
<source lang="mysql">SELECT INET_NTOA(ip) from ips; | <source lang="mysql"> | ||
INSERT INTO ips SET ip=INET_ATON('10.1.2.3'); | |||
SELECT INET_NTOA(ip) from ips; | |||
SELECT INET_NTOA(ip) from ips WHERE INET_NTOA(ip) LIKE '10.1.2.%'; | |||
</source> | |||
Alternatively, use VARCHAR(15) to store as text. | Alternatively, use VARCHAR(15) to store as text. | ||