Update WordPress MySQL tables from old domain name to new domain name


This code is typically used when migrating a WordPress site from one domain to another, ensuring that all references to the old domain are updated to the new domain.

This SQL code block updates various tables in a WordPress database to replace occurrences of the 'Old_Domain_Name' with the 'New_Domain_Name'. The specific tables being updated are:
- wp_options: Updates the option_value column for rows where the option_name is 'home' or 'siteurl'.
- wp_posts: Updates the post_content column.
- wp_postmeta: Updates the meta_value column.
- wp_usermeta: Updates the meta_value column.
- wp_links: Updates the link_url column.
- wp_comments: Updates the comment_content column.

UPDATE wp_options SET option_value = replace(option_value, 'Old_Domain_Name','New_Domain_Name') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET post_content = replace(post_content, 'Old_Domain_Name','New_Domain_Name');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'Old_Domain_Name','New_Domain_Name');

UPDATE wp_usermeta SET meta_value = replace(meta_value, 'Old_Domain_Name','New_Domain_Name');

UPDATE wp_links SET link_url = replace(link_url, 'Old_Domain_Name','New_Domain_Name');

UPDATE wp_comments SET comment_content = replace(comment_content , 'Old_Domain_Name','New_Domain_Name');

Discover more from Jorge Saldívar

Subscribe now to keep reading and get access to the full archive.

Continue reading