Change URL in WordPress database when migrating

Run these queries after migrating to make image paths point to new server.

2015.02.23 update added the find and replace technique and an external tool.

Few different methods to replace URLs in WordPress database. Handy when deploying.

Method 1: search and replace in a text editor

Just export the file, open in your favorite text editor and do a find and replace. This is not very ‘scientific’ and you need to do the importing and exporting process.

Method 2: with SQL queries

Here’s few SQL queries to replace strings in WordPress database. I’ve always ran these in phpMyAdmin, choose the DB and then the SQL tab, paste these in one by one:

UPDATE wp_posts SET guid = replace(guid, '','');
UPDATE wp_posts SET post_content = replace(post_content, '', '');
UPDATE wp_postmeta SET meta_value = replace(meta_value, '', '');

External tools

Dave in the comments links to this cool looking little tool: Search-Replace-DB.


Club-Mate, the beverage →