由于公司邮箱域名更新,由原来 @old.com 升级为 @new.com , 之前因为数据库中储存了一些个人邮箱信息,现在需要批量修改,500多人,一个个更新的话的确很难,这里推荐一个mysql数据库中一个替换函数,供大家参考。
REPLACE(str,from_str,to_str) 其中 str 代表具体的字段,from_str 为待替换的值,to_str 为替换后的新值。
如: 要将 table1 中 state 列 values 值由 1 换为 2 , replace table1 set state = replace (state , '1', '2' ) where 条件限制
在我们本题中,则为:
update user_table set email=replace(email,'@old.com','@new.com') where email like '%old.com%';