1
tedsmith
MySQL Experts read this...how to restore from a 'find and replace' tradgedy??
  • 2007/5/1 18:46

  • tedsmith

  • Home away from home

  • Posts: 1151

  • Since: 2004/6/2 1


Hi

I've got a rather major problem. I tried to save some time by using a MySQL statement to 'Find and Replace' a load of e-mail values because I had to update about 20 users with a different address and did not want to do it one at a time.

I needed to change :

user1@mysite.com
user2@mysite.com
etc

to

user1@myothersite.com
user2@myothersite.com
etc

I read
here and here that the best way to do that is like this :
update TABLE set COLUMN replace(COLUMNOLD_VALUENEW_VALUE);


So I entered this into the SQL area of phpMyAdmin :

update databaseprefix_users set email replace(email, @mysite.com, @myothersite.com);


Assuming it would find all the e-mail addresses that ended in @mysite.com and replace them with @myothersite.com. But no. It's wiped out every single e-mail address in my database!!! Now none of my users have an e-mail address associated with their account!!!

So

Q1) What went wrong?
Q2) How can I easily restore these values from my SQL backup? I don't want to risk trying to restore the entire database in case of further damage. All I want to do is restore the ..._users table, more specifically, the e-mail column of it and repopulate them with the e-mail addresses in the backup.

Any thoughts? I am rather desperate as this makes me look like a total idiot.

Thanks a lot

Ted

2
tedsmith
Re: MySQL Experts read this...how to restore from a 'find and replace' tradgedy??
  • 2007/5/1 19:04

  • tedsmith

  • Home away from home

  • Posts: 1151

  • Since: 2004/6/2 1


If it helps, I have managed to extract (from a CSV backup of the database) all the e-mail addresses of each unique username into a spreadhseet with two columns named as follows:

UserName   E-MailAddress
Joe Blog   joebloggs
@joebloggs.com


etc

How can I tell MySQL to to import the appropriate e-mail address for each username (the username column is 'uname' in table databaseprefix_users and the e-mail column is 'email')? I don't know the syntax and blindly panicked and so can't work it out!

Thanks

Ted

3
tedsmith
Re: MySQL Experts read this...how to restore from a 'find and replace' tradgedy??
  • 2007/5/1 21:03

  • tedsmith

  • Home away from home

  • Posts: 1151

  • Since: 2004/6/2 1


Got my commercial provider to restore the MySQL dump file for me. So panic over.

Would still be intrigued to have answers though for future reference

4
JCDunnart
Re: MySQL Experts read this...how to restore from a 'find and replace' tradgedy??
  • 2007/5/1 21:16

  • JCDunnart

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/7/1 5


Probably because there were no quotes around the old_value and new_value. The sql statement would assume they were columns, which don't exist, therefore email is replaced with either null or blanks.

That's my guess...

Login

Who's Online

311 user(s) are online (246 user(s) are browsing Support Forums)


Members: 0


Guests: 311


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits