Difference between revisions of "Change Wordpress URL in Database (MySQL)"

From ETCwiki
Jump to navigationJump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
This code is to search and replace an old URL with a new URL inside your Wordpress SQL database. It would be easy to paste this code into phpmyadmin in the SQL tab to run all of these. Make sure you backup your database before you do anything!
 
This code is to search and replace an old URL with a new URL inside your Wordpress SQL database. It would be easy to paste this code into phpmyadmin in the SQL tab to run all of these. Make sure you backup your database before you do anything!
  
 +
==Notes about changing Wordpress URL==
 +
Backup your site first. Backup everything. Do this wrong and things will not work.
  
 +
Fill in your old and new URL and run this in phpmyadmin.
 
  <nowiki>
 
  <nowiki>
 
  UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl.com', 'http://www.newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
 
  UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl.com', 'http://www.newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
Line 7: Line 10:
 
  UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl.com', 'http://www.newurl.com');
 
  UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl.com', 'http://www.newurl.com');
 
  UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl.com','http://www.newurl.com');
 
  UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl.com','http://www.newurl.com');
</nowiki>
+
</nowiki>
 +
 
 +
Also pop this into your wp-config.php to override the Settings page URL
 +
<nowiki>
 +
define( 'WP_HOME', 'http://example.com' );
 +
define( 'WP_SITEURL', 'http://example.com' );
 +
</nowiki>
 +
 
 +
 
 +
Now you go into the phpmyadmin search tab and look for the old url. Don't replace it here, find where it is referencing in Wordpress and change in the Wordpress Dashboard.
 +
 
 
==External Links==
 
==External Links==
 
*[https://wpbeaches.com/updating-wordpress-mysql-database-after-moving-to-a-new-url/ Updating Wordpress MySQL Database After moving to a new url]
 
*[https://wpbeaches.com/updating-wordpress-mysql-database-after-moving-to-a-new-url/ Updating Wordpress MySQL Database After moving to a new url]
  
 
[[Category:Wordpress]]
 
[[Category:Wordpress]]

Latest revision as of 15:57, 30 March 2020

This code is to search and replace an old URL with a new URL inside your Wordpress SQL database. It would be easy to paste this code into phpmyadmin in the SQL tab to run all of these. Make sure you backup your database before you do anything!

Notes about changing Wordpress URL

Backup your site first. Backup everything. Do this wrong and things will not work.

Fill in your old and new URL and run this in phpmyadmin.

 UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl.com', 'http://www.newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
 UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl.com','http://www.newurl.com');
 UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl.com', 'http://www.newurl.com');
 UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl.com','http://www.newurl.com');
 

Also pop this into your wp-config.php to override the Settings page URL

 define( 'WP_HOME', 'http://example.com' );
 define( 'WP_SITEURL', 'http://example.com' );
 


Now you go into the phpmyadmin search tab and look for the old url. Don't replace it here, find where it is referencing in Wordpress and change in the Wordpress Dashboard.

External Links