1

I've got a 40mb database file that I've exported from an old host and need to import it into a new host on a new domain. I normally open up the database in my code editor and find-replace, but as this file is so big, it's freezing my editor.

Is there a way to do this via Terminal / the command line? I saw something about using sed when searching, but I can't get my head around how it works. Is there a simple command for doing this that exists already? I tried this but it doesn't work:

sed 's/http:\/\/www.domain.com/http:\/\/www.newdomain.com/g' mydatabase.sql

Thanks for any pointers.

Osu

2
  • Are you using WP-CLI? Commented Aug 22, 2014 at 8:14
  • 1
    Hi Sven, no I'm not. Sounds like that could be another option though... Commented Aug 24, 2014 at 8:19

1 Answer 1

5

You should not use this technique to change the URL of your site : WordPress sometimes stores URLs in serialized strings. You find/replace will corrupt the serialized data and discard the whole content.

You can use interconnect/it search and replace tool to change the domain without any risk. This tool even allow you to run a dry test to check what will be modified.

EDIT 2023: this search and replace tool is now integrated in wp-cli so it is usable in command line.

If you prefer the sed technique, you should escape all special characters that have special meanings in regex like dots :

sed 's|http://www\.domain\.com|http://www\.newdomain\.com|g' mydatabase.sql
1
  • Thank you Fabien, I didn't realise a simple search and replace in the database file itself could cause so many issues. Good to know! Commented Aug 24, 2014 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.