Forums

Make a massive search and replace in mysql (5 posts)

  1. sabinou
    Member
    Posted 3 years ago #

    Hello,

    I would like to ask you guys, how can we perform a massive Search And Replace operation affecting our WHOLE database ?

    I found how to do it on some tables only, in this thread : http://wordpress.org/support/topic/188798?replies=5

    For instance, to replace a textstring in a precise field of a table :
    UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain-name.com', 'http://www.new-domain-name.com') WHERE option_name = 'home' OR option_name = 'siteurl';

    What I would like is to see the way to apply it to a COMPLETE database, on all the tables.

    With wordpress that could be done table per table, there are few tables so that would be done fast. But on other occasions, I could use that knoweledge to other bigger databases, so I'm curious to know :)

    I reckon this is a newbie question, so far I never needed to use mysql syntax, sorry :-/

    Thanks if you can help with the magic code that selects everything ;-)

    Sabinou

  2. moshu
    Member
    Posted 3 years ago #

    Not knowing exactly what you want... try this:
    http://wordpress.org/extend/plugins/search-and-replace/
    it might help.

  3. sabinou
    Member
    Posted 3 years ago #

    Erm, thank you Moshu, however, this time this won't help, I want to learn how to perform this on any database, not necessarily a wordpress-based database - and if that affects wordpress, that should be done before WP is installed, in case something doesn't work ;)

  4. moshu
    Member
    Posted 3 years ago #

    I want to learn how to perform this on any database, not necessarily a wordpress-based database

    Then go to a MySQL forum. This is a "wordpress-based" forum; not a general how-to... forum.

  5. NC@WP
    Member
    Posted 3 years ago #

    sabinou,

    how can we perform a massive Search And Replace operation affecting our WHOLE database ?

    Write a simple PHP script that would:

    1. Connect to the database,
    2. Run a SHOW TABLES query on it to get a list of tables in the database, and
    3. Run the query you want on each table in the list.

Topic Closed

This topic has been closed to new replies.

About this Topic