0

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

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

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.

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
  • 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! – Osu Aug 24 '14 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.