
WP Search & Replace
Generate SQL queries for search and replace operations in MySQL databases. Common for WordPress migrations when changing domains or URLs.

UPDATE `wp_options` SET `option_value` = REPLACE(`option_value`, 'http://old-domain.com', 'https://new-domain.com') WHERE `option_value` LIKE '%http://old-domain.com%'; UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`, 'http://old-domain.com', 'https://new-domain.com') WHERE `post_content` LIKE '%http://old-domain.com%'; UPDATE `wp_posts` SET `guid` = REPLACE(`guid`, 'http://old-domain.com', 'https://new-domain.com') WHERE `guid` LIKE '%http://old-domain.com%'; UPDATE `wp_postmeta` SET `meta_value` = REPLACE(`meta_value`, 'http://old-domain.com', 'https://new-domain.com') WHERE `meta_value` LIKE '%http://old-domain.com%'; UPDATE `wp_usermeta` SET `meta_value` = REPLACE(`meta_value`, 'http://old-domain.com', 'https://new-domain.com') WHERE `meta_value` LIKE '%http://old-domain.com%'; UPDATE `wp_comments` SET `comment_content` = REPLACE(`comment_content`, 'http://old-domain.com', 'https://new-domain.com') WHERE `comment_content` LIKE '%http://old-domain.com%'; UPDATE `wp_comments` SET `comment_author_url` = REPLACE(`comment_author_url`, 'http://old-domain.com', 'https://new-domain.com') WHERE `comment_author_url` LIKE '%http://old-domain.com%';
wp search-replace 'http://old-domain.com' 'https://new-domain.com' --all-tables --dry-run # Remove --dry-run when ready to execute
When you need this
The most common scenario is a domain migration — moving WordPress from a staging URL to a live domain, or switching from HTTP to HTTPS. WordPress stores full URLs in the database for post content, option values, widget data, and serialized arrays. A simple find-and-replace in a SQL dump will break serialized data because the string lengths no longer match. This tool generates queries that handle both plain strings and serialized PHP arrays correctly.
Why serialized data matters
WordPress uses PHP serialization to store complex data like widget settings, theme options, and plugin configurations. A serialized string looks like s:23:"http://old-domain.com/"; — the s:23 means the string is exactly 23 characters long. If you replace old-domain.com with new-domain.com using a raw SQL REPLACE, the string length changes but the byte count prefix stays the same. WordPress then fails to unserialize the data and your widgets, menus, and plugin settings silently break. The generated SQL accounts for this by recalculating lengths.
Best practices for migrations
Always back up your database before running search-replace queries. Test on a staging copy first if possible. Run the queries in order — do the largest replacements first (full URLs with protocol), then shorter variations. After replacing, flush the WordPress object cache and visit Settings → Permalinks to regenerate rewrite rules. If you use a CDN, purge it after the migration completes.
Related Tools
WP Admin Generator
Generate SQL queries to create WordPress admin accounts instantly. Useful when locked out or need quick database-level access.
WP Permissions Fixer
Generate correct chmod and chown commands to fix WordPress file and folder permissions.
htpasswd Generator
Generate Apache .htpasswd entries for basic authentication with MD5, SHA-1, or plain text hashing.