Skip to main content

VillageSQL is a drop-in replacement for MySQL with extensions.

All examples in this guide work on VillageSQL. Install Now →
MAC addresses in MySQL are typically stored as 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)

Both rows insert. Now you have two representations of the same vendor prefix in the same column. Deduplication queries become string normalization problems. There’s no enforcement that the column actually holds a valid MAC address.

The Standard Workaround: BINARY(6)

Compact storage: convert to binary on insert, back to string on read.
That’s the manual reconstruct. It works but it’s verbose and fragile, and it still doesn’t validate the input.

With VillageSQL: MACADDR and MACADDR8

VillageSQL’s vsql_network_address extension adds MACADDR (6-byte IEEE 802 format) and MACADDR8 (8-byte EUI-64 format) types with automatic format normalization and validation.
Output:

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. The MACADDR8 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 (inserting ff:fe in the middle), do it in application code before calling macaddr8_from_string().

Troubleshooting

See also