Data masking in MariaDB hides sensitive information on-the-fly with built-in masking functions and privilege checks.
Protect PII, comply with GDPR/PCI, and let analysts query production data without exposing emails or card numbers. Masking functions return obfuscated values at query time, so no copy of raw data is created.
MariaDB Server 10.4+ ships the "data_masking" plugin. After INSTALL SONAME 'data_masking', functions such as mask_inner()
, mask_outer()
, mask_pan()
, and digit-specific variants obfuscate strings or numbers.Users with the UNMASK privilege see real data; everyone else sees masked output.
Grant UNMASK to roles that must see clear text: GRANT UNMASK ON *.* TO 'admin'@'%';
. Grant SHOW_ROUTINE and EXECUTE if functions are used in stored routines. Revoke UNMASK from analysts to enforce masking.
Select emails with only the first character visible: SELECT mask_outer(email, '@', 1, 0) AS email_masked FROM Customers;
.Analysts see "a*****@domain.com"; admins with UNMASK see the full address.
SELECT mask_pan('4111111111111111');
returns "411111******1111". Replace literal with column name in payment table.
Yes. Create a view limiting access: CREATE VIEW v_customers AS SELECT id, name, mask_outer(email,'@',1,0) AS email FROM Customers;
. Analysts query the view; admins query the base table.
Store GRANT/REVOKE scripts with schema migrations.Review UNMASK grants during audits to ensure least-privilege access.
Data masking only protects at query time. If users can dump tables or access backups, masking is bypassed. Combine with encryption, strict backup policies, and audit logging.
.
Overhead is minimal because functions operate per row in memory. Indexes on masked columns are not used, so filter on raw columns when possible.
Yes. Extract the JSON element first, then apply masking: SELECT mask_inner(JSON_EXTRACT(details,'$.phone'),4)
.
No. Backups capture raw table data. Use encryption-at-rest and restrict backup access in addition to masking.