NYCPHP Meetup

NYPHP.org

[nycphp-talk] Replacing a string within many tables, unknown c olumns

Lynn, Michael (DCS) MLynn at exchange.ml.com
Fri Feb 14 11:22:54 EST 2003


Thanks for the quick response...

I think I found a non-php way to do this:

Mysqldump PROD_DBNAME > PROD_DBNAME.sql; # backup
Mysqadmin drop PROD_DBNAME
Mysqladmin create PROD_DBNAME
Mysqldump DEV_DBNAME | sed 's/OLD_STRING/NEW_STRING/g' | mysql PROD_DBNAME

Or something close to that.

I'm also working on a php way to do it and would appreciate any input from someone who's done something similar... I'll forward my code when it's working.

Thanks again.

Regards,
Mike

-----Original Message-----
From: Chris Snyder [mailto:chris at psydeshow.org] 
Sent: Friday, February 14, 2003 11:04 AM
To: NYPHP Talk
Subject: Re: [nycphp-talk] Replacing a string within many tables, unknown columns


Lynn, Michael wrote:

>I need to be able to replace every occurance of a string in many 
>tables, many columns.  The string appears in tables in various places 
>and usually embedded in a string type or var type column... The string 
>will not be the entire contents of the column so a replace won't work.
>
>Eg: my development database contains url links to the development web 
>site.  When I copy the tables to production, I want to search and 
>replace every occurance of the development urls with production urls 
>throughout the entire database.
>
>  
>
Many columns, many tables? Ouch.

It seems like the best way to do this, since you're migrating the data 
anyway, is to take the contents of the mysqldump you do to get the data 
out of your development database, and run a search-and-replace operation 
on it before feeding it into the production database.

See mysqldump in the "Backing up your database" section of the MySQL 
documentation-- the sql file you get is plain text, and the data therein 
is processable in a myriad of ways as long as you don't distrub the SQL 
itself.

    chris.

-- 
HIP HOP CLOWN MONTH
booth of the day: all day, every day http://hiphopclown.org/berylium/showcase/




--- Unsubscribe at http://nyphp.org/list/ ---






More information about the talk mailing list