Bulk update in MYSQL -
I have a table with data about some users.
Many of them have updated their email system at OLDHOST.com for a new system at NEWHOST.com. All user usernames are the same, so if you had dave@oldHOST.com, then you are now dave@NEWHOST.com
A better way to change all the email fields in the user table without selecting All the lines that say in PHP, then check whether the email is oldhost, then the string is being converted to NEWHOST?
Is there a great SQL statement to help with this?
Example of some table (simplified)
id | First name Surname Email ------------------------------------------------ 1 | Dave | Smith | A21dsmith@oldHOST.com 2 | Barry | Jones | A21bjones@oldHOST.com
etc.
All who need to change are all emails containing OLHDHOST (not all) NEWHOST.
You must replace the corresponding part of each string within a statement, Note: REPLACE () is case-sensitive, so that you can use This will also change all of your email addresses in lowercase, so be aware of it :) @ and change it
update table SET email = REPLACE (email, 'OLDHOST.com', 'newhost.com');
LOWER (email)
inside the REPLACE function To catch the possibilities of all cases if you need to, as shown below:
update table SET email = REPLACE (lower (email), 'oldhost dot com', 'newhost dot com');
Comments
Post a Comment