I have a MySQL database full of user information. I'd like to give it to a contractor to do some analysis, but I don't want to expose all of my user information. My biggest concern now are the email addresses. I would like to keep the email address domain, but anonymize the address. Ideally, I'd like to to it in a SQL script.

So I'd like to take every item in the 'email' column and turn it from 'myAddress@gmail.com' to 'xxxx@gmail.com' and 'anotherAddress@hotmail.com' to 'xxxx@hotmail.com'. Any ideas?

有帮助吗?

解决方案

UPDATE YourTable
    SET EmailColumn = 'xxx' + RIGHT(EmailColumn, LENGTH(EmailColumn) - LOCATE('@', EmailColumn) + 1)

其他提示

UPDATE YourTable SET EmailColumn = CONCAT( 'xxx', RIGHT(EmailColumn, LENGTH(EmailColumn) - LOCATE('@', user_email) + 1) )
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top