VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
VARCHAR(17). That stores them, but it accepts any string, normalizes nothing, and costs 17 bytes when 6 would do. VillageSQL’s MACADDR type validates format on insert, normalizes to a consistent representation, and gives you OUI extraction for free.
The MySQL Default: VARCHAR(17)
The Standard Workaround: BINARY(6)
Compact storage: convert to binary on insert, back to string on read.With VillageSQL: MACADDR and MACADDR8
VillageSQL’svsql_network_address extension adds MACADDR (6-byte IEEE 802 format) and MACADDR8 (8-byte EUI-64 format) types with automatic format normalization and validation.
OUI extraction
The first 3 bytes of a MAC address identify the manufacturer (OUI — Organizationally Unique Identifier).macaddr_trunc() zeroes the last 3 bytes, leaving only the OUI:
Comparison and sorting
EUI-64 MAC addresses (MACADDR8)
Modern hardware increasingly uses 8-byte EUI-64 identifiers. TheMACADDR8 type handles these:
Comparing Approaches
Frequently Asked Questions
Does MACADDR accept uppercase hex?
Yes —08:00:2B:01:02:03 and 08:00:2b:01:02:03 both parse correctly and store identically.
Can I use MACADDR as a primary key?
Yes.MACADDR supports indexing and equality comparisons. For network device tables where the MAC is the natural identifier, it’s a reasonable primary key.
What’s the difference between MACADDR and MACADDR8?
MACADDR is the 6-byte IEEE 802 MAC-48 format used by most network hardware. MACADDR8 is the 8-byte EUI-64 format used in some modern network interfaces and IPv6 link-local address generation. Use MACADDR8 when you’re storing EUI-64 identifiers.
How do I convert between MACADDR and MACADDR8?
No built-in conversion function. If you need to expand a MAC-48 to EUI-64 (insertingff:fe in the middle), do it in application code before calling macaddr8_from_string().
Troubleshooting
See also
- Storing IP Addresses in MySQL — the same network address storage pattern for IPs

