Change WordPress post URLs in mysql

I’ve had to move word­press core and/or the wp-content direc­tory around before and I needed to change URLs within the post body to direct to the new loca­tion. Run­ning this query in mysql will update all of your post con­tent (links, images, etc.):

UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://example.com/old-directory', 'http://example.com/new-directory');

You’ll also want to update the guid column

UPDATE wp_posts SET guid = REPLACE(guid, 'http://example.com/old-directory', 'http://example.com/new-directory');