How to mask user email addresses with a different domain in MySQL?


Let us first create a table −

mysql> create table DemoTable1345
   -> (
   -> UserEmailAddress text
   -> );
Query OK, 0 rows affected (0.42 sec)

Insert some records in the table using insert command. We have inserted email address here −

mysql> insert into DemoTable1345 values('Carol123@gmail.com');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable1345 values('987Sam@gmail.com');
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable1345 values('David_Miller@gmail.com');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable1345 values('Bob@gmail.com');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1345;

This will produce the following output −

+------------------------+
| UserEmailAddress       |
+------------------------+
| Carol123@gmail.com     |
| 987Sam@gmail.com       |
| David_Miller@gmail.com |
| Bob@gmail.com          |
+------------------------+
4 rows in set (0.00 sec)

Following is the query to mask user email addresses with different domains in MySQL −

mysql> update DemoTable1345 set UserEmailAddress=replace(UserEmailAddress, '@gmail.com','@amz.com');
Query OK, 4 rows affected (0.18 sec)
Rows matched: 4 Changed: 4 Warnings: 0

Let us check the table records once again −

mysql> select * from DemoTable1345;

This will produce the following output −

+----------------------+
| UserEmailAddress     |
+----------------------+
| Carol123@amz.com     |
| 987Sam@amz.com       |
| David_Miller@amz.com |
| Bob@amz.com          |
+----------------------+
4 rows in set (0.00 sec)

Updated on: 05-Nov-2019

383 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements