Results 1 to 2 of 2

Thread: Replace text in mysql dump file

  1. #1
    Join Date
    May 2013
    Beans
    4

    Replace text in mysql dump file

    Hi everyone,
    I have a mysql dump file, which is a database of social wordpress blog. In it there are about 800 blogs that have been made, the company where I currently work change their domain, and they don't want to lose the blogs. what i need is changing the domain in that dump database. How to do the replacement domain with awk?


    how to do this with awk ?
    searching for the "old domain" and replace with a "new domain".


    i did it with notepad++ in windows before, but didn't work well.


    or maybe there's is the other way? the better way?


    thanks

  2. #2
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    12,964
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Replace text in mysql dump file

    Actually you want to use sed:

    Code:
    sed 's/old_domain/new_domain/g' < olddb.sql > newdb.sql
    If the domain is something like example.com, "escape" the dot like this:

    Code:
    sed 's/example\.com/newdomain.com/g' < ...
    The first entry is a regular expression, but the replacement text is just a string. I enclosed the command in single quotes to force bash to treat the whole thing as a literal.

    Make sure you have backups of the original dump before proceeding. Even though the procedure above will create a new file, it's always good to have backups just in case.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •