YeahMKD
YeahMKD

Reputation: 425

Replace website url in wordpress database

Im transfering a wordpress site from one domain to another. got the db integrated and the files in through FTP.

How do I replace all of the DB entries from http://url1.com to http://url2.com?

I tried this through SQL but it didnt work.

SELECT REPLACE('www.url1.com', 'url1', 'url2');

Upvotes: 0

Views: 2032

Answers (3)

Vignesh Kamath
Vignesh Kamath

Reputation: 69

Use Better Search Replace Plugin.

https://wordpress.org/plugins/better-search-replace/

It is very simple. Before it replaces anything in the database, it will show the number rows that will be affected by running a Dry Run.

I recently used it and it worked flawlessly.

Upvotes: 1

Manoj Dhiman
Manoj Dhiman

Reputation: 5166

sqldump to a text file, find/replace, re-import the sqldump.

or

run queries to update in each table where you need to replace

UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com','http://newdomain.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');

Upvotes: 2

Chris Herbert
Chris Herbert

Reputation: 6305

Taken from the first search results for "mysql find replace":

update [table_name]
set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');

If you're moving from a development or staging server to a production server, I'd suggest making the links relative rather than changing them to a different absolute URL.

Upvotes: 0

Related Questions