MySQL one-liner to obfuscate live user details

Problem: you need to get someone else to set up your web application on another server. Even with a signed NDA it’s not really a good idea to be sending over MySQL dumps containing real people’s details and it is almost certainly against data protection rules.

If so, and you need to do it right now, then this’ll do you nicely as a quick & dirty hack. Clearly, if you had some more time then you could come up with something a bit more elegant.

UPDATE some_table
/** in this case it's an email address */
SET username = CONCAT(SUBSTRING(MD5(RAND()), -10), "@", SUBSTRING(MD5(RAND()), -10), ".com"), 
/** this might be some IDs that you want to remain unchanged, say a test login */
WHERE (id != 1);Code language: SQL (Structured Query Language) (sql)


Leave a Reply

Your email address will not be published. Required fields are marked *