Solved

MySQL update statement help

Posted on 2013-05-20
3
432 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

18 Experts available now in Live!

Get 1:1 Help Now