Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Go Search Replace

Build Status

Search & replace URLs in WordPress SQL files.

cat | search-replace >


Migrating WordPress databases often requires replacing domain names. This is a complex operation because WordPress stores PHP serialized data, which encodes string lengths. The common method uses PHP to unserialize the data, do the search/replace, and then re-serialize the data before writing it back to the database. Here we replace strings in the SQL file and then fix the string lengths.


Replacing strings in a SQL file can be dangerous. We have to be careful not to modify the structure of the file in a way that would corrupt the file. For this reason, we're limiting the search domain to roughly include characters that can be used in domain names. Since the most common usage for search-replace is changing domain names or switching http: to https:, this is an easy way to avoid otherwise complex issues.


This package requires Go. An easy way to install Go on a Mac is with Homebrew.

Note the changes you need to make to your PATH and that you have to either restart your terminal or source your shell rc file.

You need to install Gox which you can install with go install

Once that's installed you can install this tool with the following command: go install

Go is set up by convention, not configuration so your files likely live in a directory like: /Users/user/go/src/

Nagivage to that directory and run make

go-search-replace will be ready for you to use. Once built you won't have to complete any of the above steps again.