Solved

MySQL update statement help

Posted on 2013-05-20
3
434 Views
Last Modified: 2013-06-05
Hi,
I have mysql table with following data.
I need a small change ,I need to alter email address as below.

Each email like cruz.ashley62@testmail.com need to change as cruz.ashley62+ mydomain@gmail.com
How can I write an update statement for it?

pluto.server2013-05-20-20-21-30-pluto.server.png
0
Comment
Question by:crazywolf2010
  • 2
3 Comments
 
LVL 20

Expert Comment

by:dsacker
ID: 39182346
update YourTable
set email = replace(email, 'testmail.com', 'gmail.com')
where email like '%testmail.com'
0
 
LVL 20

Assisted Solution

by:dsacker
dsacker earned 250 total points
ID: 39182351
I saw the need to append mydomain. You would do that like this:

update YourTable
set email = replace(email, '@testmail.com', mydomain + '@gmail.com')
where email like '%testmail.com'
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39182765
I think I would do it this way...

1. Back up the table
2. ALTER TABLE to add a new column, maybe called newEmail
3. SELECT the id and email columns from all the rows and copy them into the newEmail column.
4. SELECT the id and email columns for the rows you want to change.
5. Reformat the email and UPDATE the newEmail column according to a WHERE match on id.
6. Use phpMyAdmin or similar tool to verify that all the changes look right.
7. ALTER TABLE to remove the email column and rename the newEmail column to email.

This strategy may seem slow and plodding, but it allows you and others to use the table while the maintenance is going on.  And if things get screwed up, you have a stable restart point at Step#3.

best of luck with it, ~Ray
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
A short film showing how OnPage and Connectwise integration works.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now