Solved

MySQL update statement help

Posted on 2013-05-20
3
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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

Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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