MySQL anonymize e-mail

26 07 2011

Working with MySQL I encountered a task I’ve never faced before. I had to anonymize (mask) e-mail addresses in a table. In first attempt I googled this article on StackOverflow. That give me a feeling that some functions useful for this issue should be already implemented in MySQL. I was right. I found string functions documentation and finally I ended up with the following solution:

select concat(substring_index(email, '@', 1), '') from societe;

It changes e-mails from:


Alternatively, you can change username and leave the string after ‘@’.

select concat('user@', substring_index(email, '@', -1)) from societe;

And the result is:




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: