change email address in mysql

A tiny piece of SQL to update email addresses in a table where the domain is changing:

update aliases set emailaddr = concat(SUBSTRING_INDEX(emailaddr, '@', 1),
'@newdomain.com') where emailaddr like '%@olddomain.com';

Very simple, but this has been hanging around in draft for ages and it may help someone.

Leave a Reply

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