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
| Approach | Storage | Validates format | Normalizes input | OUI extraction |
|---|---|---|---|---|
VARCHAR(17) | 17 bytes | No | No | Manual string slice |
BINARY(6) + manual UNHEX | 6 bytes | No | No | Manual binary mask |
MACADDR (VillageSQL) | 6 bytes | Yes | Yes (colon format) | macaddr_trunc() |
MACADDR8 (VillageSQL) | 8 bytes | Yes | Yes | — |
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
| Problem | Solution |
|---|---|
FUNCTION macaddr_from_string does not exist | Run INSTALL EXTENSION vsql_network_address |
macaddr_from_string() returns NULL | Input is not a valid MAC address format |
| OUI query returns no results | Check that you’re comparing against a full 6-byte truncated MAC: macaddr_from_string('xx:xx:xx:00:00:00') |
| Mixed MAC formats not matching in WHERE | They will match — MACADDR normalizes all formats on insert |

