<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>database search replace Archives - WP-CLI Mastery</title>
	<atom:link href="https://wpclimastery.com/blog/tag/database-search-replace/feed/" rel="self" type="application/rss+xml" />
	<link>https://wpclimastery.com/blog/tag/database-search-replace/</link>
	<description>Automate WordPress Like a DevOps Pro.</description>
	<lastBuildDate>Mon, 24 Nov 2025 11:16:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wpclimastery.com/wp-content/uploads/2025/11/cropped-favicon-32x32.webp</url>
	<title>database search replace Archives - WP-CLI Mastery</title>
	<link>https://wpclimastery.com/blog/tag/database-search-replace/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WP-CLI Search-Replace: Safe Database Modifications for WordPress Migration</title>
		<link>https://wpclimastery.com/blog/wp-cli-search-replace-safe-database-modifications-for-wordpress-migration/</link>
		
		<dc:creator><![CDATA[Krasen]]></dc:creator>
		<pubDate>Sun, 25 Jan 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[Advanced WP-CLI Techniques]]></category>
		<category><![CDATA[database search replace]]></category>
		<category><![CDATA[wordpress database migration]]></category>
		<category><![CDATA[wordpress url change]]></category>
		<category><![CDATA[wp-cli db]]></category>
		<category><![CDATA[wp-cli search-replace]]></category>
		<guid isPermaLink="false">https://wpclimastery.com/?p=138</guid>

					<description><![CDATA[<p>Changing URLs in WordPress databases manually destroys serialized data, breaks widget settings, corrupts option values, and leaves your site unusable. MySQL find-replace queries seem simple until you realize WordPress stores...</p>
<p>The post <a href="https://wpclimastery.com/blog/wp-cli-search-replace-safe-database-modifications-for-wordpress-migration/">WP-CLI Search-Replace: Safe Database Modifications for WordPress Migration</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Changing URLs in WordPress databases manually destroys serialized data, breaks widget settings, corrupts option values, and leaves your site unusable. MySQL find-replace queries seem simple until you realize WordPress stores array lengths in serialized strings—one wrong replacement breaks everything.</p>



<p>WP-CLI’s <code>search-replace</code> command handles serialized data automatically, validates replacements before executing, and shows exactly what changed. It’s the only safe way to modify WordPress database content at scale.</p>



<p>In this guide, you’ll master WP-CLI search-replace for site migrations, domain changes, protocol updates, and any database modification requiring precision and safety.</p>



<h3 class="wp-block-heading" id="why-search-replace">Why WP-CLI Search-Replace is Critical</h3>



<p><a href="https://www.php.net/manual/en/function.serialize.php">WordPress serialized data</a> contains length values that break when modified with simple find-replace operations.</p>



<h4 class="wp-block-heading" id="problems-with-manual-database-search-replace">Problems with Manual Database Search-Replace</h4>



<p><strong>Serialized data corruption</strong>: Direct MySQL replacement breaks array and object serialization.</p>



<p><strong>Partial replacements</strong>: URLs in JSON, meta fields, and options get missed.</p>



<p><strong>No validation</strong>: Can’t preview changes before executing them.</p>



<p><strong>No reporting</strong>: Don’t know what was changed or how many replacements occurred.</p>



<p><strong>Irreversible</strong>: Once executed, can’t undo without restoring backups.</p>



<h4 class="wp-block-heading" id="wp-cli-search-replace-advantages">WP-CLI Search-Replace Advantages</h4>



<p><strong>Serialization-safe</strong>: Automatically recalculates lengths in serialized strings.</p>



<p><strong>Dry-run mode</strong>: Preview all changes before executing them.</p>



<p><strong>Comprehensive</strong>: Searches all tables, columns, and data types.</p>



<p><strong>Detailed reporting</strong>: Shows exactly what will change and where.</p>



<p><strong>Table-specific</strong>: Target specific tables or exclude sensitive data.</p>



<p>According to <a href="https://wpengine.com/">WordPress migration studies</a>, 80% of failed migrations are due to incorrect URL replacement breaking serialized data.</p>



<h3 class="wp-block-heading" id="fundamentals">Search-Replace Fundamentals</h3>



<p>Master basic search-replace operations safely.</p>



<h4 class="wp-block-heading" id="basic-search-replace-syntax">Basic Search-Replace Syntax</h4>



<div class="sourceCode" id="cb1">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true"></a><span class="co"># Basic replacement</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old-text'</span> <span class="st">'new-text'</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true"></a></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true"></a><span class="co"># Replace in specific tables</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> wp_posts wp_postmeta</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true"></a><span class="co"># Replace in all tables (dangerous, use carefully)</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --all-tables</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true"></a></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true"></a><span class="co"># Skip specific columns</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --skip-columns=guid</span></code></pre>
</div>



<h4 class="wp-block-heading" id="always-use-dry-run-first">Always Use Dry-Run First</h4>



<div class="sourceCode" id="cb2">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true"></a><span class="co"># Preview changes without executing (CRITICAL!)</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'oldsite.com'</span> <span class="st">'newsite.com'</span> --dry-run</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true"></a><span class="co"># Dry-run with detailed report</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'http://'</span> <span class="st">'https://'</span> --dry-run --report</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true"></a><span class="co"># See exact replacement count</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --dry-run --report --precise</span></code></pre>
</div>



<p><strong>Critical Rule</strong>: NEVER run search-replace without <code>--dry-run</code> first. Always preview changes.</p>



<h4 class="wp-block-heading" id="understanding-serialized-data">Understanding Serialized Data</h4>



<div class="sourceCode" id="cb3">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true"></a><span class="co"># WordPress serialized data example:</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true"></a><span class="co"># a:3:{s:4:"name";s:4:"John";s:3:"age";i:30;}</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true"></a><span class="co">#      ^ length     ^ length</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true"></a><span class="co"># Direct MySQL replacement breaks this:</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true"></a><span class="co"># UPDATE wp_options SET option_value =</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true"></a><span class="co"># REPLACE(option_value, 'John', 'Jonathan');</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true"></a><span class="co"># Result: a:3:{s:4:"name";s:8:"Jonathan";...}</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true"></a><span class="co">#                        ^ WRONG! Should be s:8</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true"></a></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true"></a><span class="co"># WP-CLI handles this automatically:</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'John'</span> <span class="st">'Jonathan'</span> wp_options</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true"></a></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true"></a><span class="co"># WP-CLI recalculates: s:4 becomes s:8 automatically</span></span></code></pre>
</div>



<p>Learn more about <a href="https://developer.wordpress.org/cli/commands/search-replace/">WP-CLI search-replace documentation</a>.</p>



<h3 class="wp-block-heading" id="use-cases">Common Search-Replace Use Cases</h3>



<p>Handle the most frequent WordPress database modification scenarios.</p>



<h4 class="wp-block-heading" id="domain-migration">Domain Migration</h4>



<div class="sourceCode" id="cb4">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true"></a><span class="co"># migrate-domain.sh - Complete domain change</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true"></a></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true"></a><span class="va">OLD_DOMAIN=</span><span class="st">"oldsite.com"</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true"></a><span class="va">NEW_DOMAIN=</span><span class="st">"newsite.com"</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true"></a></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true"></a><span class="co"># Backup first (ALWAYS!)</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true"></a><span class="ex">wp</span> db export backup-before-domain-change.sql.gz</span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true"></a></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true"></a><span class="co"># Dry-run to preview</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Previewing changes..."</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"https://</span><span class="va">$OLD_DOMAIN</span><span class="st">"</span> <span class="st">"https://</span><span class="va">$NEW_DOMAIN</span><span class="st">"</span> --dry-run --report</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true"></a></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true"></a><span class="co"># Ask for confirmation</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true"></a><span class="bu">read</span> -p <span class="st">"Proceed with replacement? (y/n) "</span> -n 1 -r</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true"></a><span class="bu">echo</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true"></a><span class="kw">if [[</span> <span class="ot">!</span> <span class="va">$REPLY</span> =~ ^[Yy]$<span class="kw"> ]]</span>; <span class="kw">then</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Operation cancelled"</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true"></a>    <span class="bu">exit</span> 0</span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true"></a></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true"></a><span class="co"># Execute replacements</span></span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Executing replacements..."</span></span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true"></a></span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true"></a><span class="co"># Replace full URLs</span></span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"https://</span><span class="va">$OLD_DOMAIN</span><span class="st">"</span> <span class="st">"https://</span><span class="va">$NEW_DOMAIN</span><span class="st">"</span></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"http://</span><span class="va">$OLD_DOMAIN</span><span class="st">"</span> <span class="st">"https://</span><span class="va">$NEW_DOMAIN</span><span class="st">"</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true"></a></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true"></a><span class="co"># Replace protocol-relative URLs</span></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"//</span><span class="va">$OLD_DOMAIN</span><span class="st">"</span> <span class="st">"//</span><span class="va">$NEW_DOMAIN</span><span class="st">"</span></span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true"></a></span>
<span id="cb4-32"><a href="#cb4-32" aria-hidden="true"></a><span class="co"># Update WordPress options directly</span></span>
<span id="cb4-33"><a href="#cb4-33" aria-hidden="true"></a><span class="ex">wp</span> option update home <span class="st">"https://</span><span class="va">$NEW_DOMAIN</span><span class="st">"</span></span>
<span id="cb4-34"><a href="#cb4-34" aria-hidden="true"></a><span class="ex">wp</span> option update siteurl <span class="st">"https://</span><span class="va">$NEW_DOMAIN</span><span class="st">"</span></span>
<span id="cb4-35"><a href="#cb4-35" aria-hidden="true"></a></span>
<span id="cb4-36"><a href="#cb4-36" aria-hidden="true"></a><span class="co"># Flush caches</span></span>
<span id="cb4-37"><a href="#cb4-37" aria-hidden="true"></a><span class="ex">wp</span> cache flush</span>
<span id="cb4-38"><a href="#cb4-38" aria-hidden="true"></a><span class="ex">wp</span> rewrite flush</span>
<span id="cb4-39"><a href="#cb4-39" aria-hidden="true"></a></span>
<span id="cb4-40"><a href="#cb4-40" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Domain migration complete"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="http-to-https-migration">HTTP to HTTPS Migration</h4>



<div class="sourceCode" id="cb5">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true"></a><span class="co"># migrate-to-https.sh</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true"></a></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true"></a><span class="va">DOMAIN=</span><span class="st">"example.com"</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true"></a></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true"></a><span class="co"># Backup</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true"></a><span class="ex">wp</span> db export backup-before-https.sql.gz</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true"></a></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true"></a><span class="co"># Dry-run</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"http://</span><span class="va">$DOMAIN</span><span class="st">"</span> <span class="st">"https://</span><span class="va">$DOMAIN</span><span class="st">"</span> --dry-run</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true"></a></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true"></a><span class="co"># Execute</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"http://</span><span class="va">$DOMAIN</span><span class="st">"</span> <span class="st">"https://</span><span class="va">$DOMAIN</span><span class="st">"</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true"></a></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true"></a><span class="co"># Update options</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true"></a><span class="ex">wp</span> option update home <span class="st">"https://</span><span class="va">$DOMAIN</span><span class="st">"</span></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true"></a><span class="ex">wp</span> option update siteurl <span class="st">"https://</span><span class="va">$DOMAIN</span><span class="st">"</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true"></a></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Migrated to HTTPS"</span></span></code></pre>
</div>



<p><strong>Use Case</strong>: Essential for SEO and security—Google requires HTTPS for ranking.</p>



<h4 class="wp-block-heading" id="path-changes-subdirectory-moves">Path Changes (Subdirectory Moves)</h4>



<div class="sourceCode" id="cb6">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true"></a><span class="co"># Move from subdirectory to root</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'https://example.com/blog'</span> <span class="st">'https://example.com'</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true"></a><span class="co"># Move from root to subdirectory</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'https://example.com'</span> <span class="st">'https://example.com/wordpress'</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true"></a></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true"></a><span class="co"># Move between subdirectories</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'https://example.com/old'</span> <span class="st">'https://example.com/new'</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="content-text-replacement">Content Text Replacement</h4>



<div class="sourceCode" id="cb7">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true"></a><span class="co"># Replace company name in all content</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'Old Company LLC'</span> <span class="st">'New Company Inc'</span> wp_posts</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true"></a></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true"></a><span class="co"># Fix common typos across site</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'recieve'</span> <span class="st">'receive'</span> wp_posts wp_postmeta</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true"></a></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true"></a><span class="co"># Update email addresses</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'contact@oldcompany.com'</span> <span class="st">'contact@newcompany.com'</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true"></a></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true"></a><span class="co"># Replace shortcodes</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'[old_shortcode]'</span> <span class="st">'[new_shortcode]'</span> wp_posts</span></code></pre>
</div>



<h3 class="wp-block-heading" id="advanced-techniques">Advanced Search-Replace Techniques</h3>



<p>Handle complex scenarios with precision.</p>



<h4 class="wp-block-heading" id="regex-pattern-replacement">Regex Pattern Replacement</h4>



<div class="sourceCode" id="cb8">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true"></a><span class="co"># Enable regex mode</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'pattern'</span> <span class="st">'replacement'</span> --regex</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true"></a></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true"></a><span class="co"># Replace all HTTP/HTTPS variations</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'https?://oldsite\.com'</span> <span class="st">'https://newsite.com'</span> --regex</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true"></a></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true"></a><span class="co"># Remove URL parameters</span></span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'\?utm_[^\s"]+'</span> <span class="st">''</span> --regex wp_posts</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true"></a></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true"></a><span class="co"># Fix malformed URLs</span></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'http://http://'</span> <span class="st">'http://'</span> --regex</span></code></pre>
</div>



<p><strong>Warning</strong>: Test regex patterns thoroughly with <code>--dry-run</code>. Incorrect patterns cause unexpected replacements.</p>



<h4 class="wp-block-heading" id="table-specific-operations">Table-Specific Operations</h4>



<div class="sourceCode" id="cb9">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true"></a><span class="co"># Replace in posts and metadata only</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> wp_posts wp_postmeta</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true"></a></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true"></a><span class="co"># Replace in all tables except options</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --all-tables-with-prefix --skip-tables=wp_options</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true"></a></span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true"></a><span class="co"># List all tables first</span></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true"></a><span class="ex">wp</span> db tables</span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true"></a></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true"></a><span class="co"># Replace in custom tables</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> wp_custom_table</span></code></pre>
</div>



<h4 class="wp-block-heading" id="export-replacement-report">Export Replacement Report</h4>



<div class="sourceCode" id="cb10">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="co"># Generate CSV report of all changes</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --export=changes.csv</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true"></a></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true"></a><span class="co"># Generate report with dry-run</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --dry-run --report <span class="op">&gt;</span> replacement-report.txt</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true"></a></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true"></a><span class="co"># Count replacements</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true"></a><span class="va">REPLACEMENTS=$(</span><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --dry-run --format=count<span class="va">)</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Will replace </span><span class="va">$REPLACEMENTS</span><span class="st"> occurrences"</span></span></code></pre>
</div>



<p>Learn about <a href="https://wordpress.org/support/article/database-description/">WordPress database tables</a> structure.</p>



<h4 class="wp-block-heading" id="skip-sensitive-columns">Skip Sensitive Columns</h4>



<div class="sourceCode" id="cb11">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="co"># Don't modify GUIDs (recommended)</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --skip-columns=guid</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a><span class="co"># Skip multiple columns</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --skip-columns=guid,post_date</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true"></a></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true"></a><span class="co"># Skip user passwords and meta</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> wp_users --skip-columns=user_pass</span></code></pre>
</div>



<p><strong>Best Practice</strong>: Always skip <code>guid</code> column—changing GUIDs breaks feed readers and external references.</p>



<h3 class="wp-block-heading" id="safe-migration">Safe Migration Workflow</h3>



<p>Complete migration process with validation and rollback capability.</p>



<h4 class="wp-block-heading" id="complete-migration-script">Complete Migration Script</h4>



<div class="sourceCode" id="cb12">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true"></a><span class="kw">set</span> <span class="ex">-euo</span> pipefail</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true"></a></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true"></a><span class="co"># Configuration</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true"></a><span class="va">SOURCE_URL=</span><span class="st">"https://staging.example.com"</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true"></a><span class="va">TARGET_URL=</span><span class="st">"https://example.com"</span></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true"></a><span class="va">BACKUP_DIR=</span><span class="st">"/backups"</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true"></a><span class="va">LOG_FILE=</span><span class="st">"/var/log/migration.log"</span></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true"></a></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true"></a><span class="fu">log()</span> <span class="kw">{</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"[</span><span class="va">$(</span><span class="fu">date</span> <span class="st">'+%Y-%m-%d %H:%M:%S'</span><span class="va">)</span><span class="st">] </span><span class="va">$@</span><span class="st">"</span> <span class="kw">|</span> <span class="fu">tee</span> -a <span class="st">"</span><span class="va">$LOG_FILE</span><span class="st">"</span></span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true"></a><span class="kw">}</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true"></a></span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"=== WordPress Migration Started ==="</span></span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true"></a></span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true"></a><span class="co"># Validate WordPress</span></span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true"></a><span class="kw">if</span> ! <span class="ex">wp</span> core is-installed<span class="kw">;</span> <span class="kw">then</span></span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true"></a>    <span class="ex">log</span> <span class="st">"ERROR: WordPress not installed"</span></span>
<span id="cb12-19"><a href="#cb12-19" aria-hidden="true"></a>    <span class="bu">exit</span> 1</span>
<span id="cb12-20"><a href="#cb12-20" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb12-21"><a href="#cb12-21" aria-hidden="true"></a></span>
<span id="cb12-22"><a href="#cb12-22" aria-hidden="true"></a><span class="co"># Create backup</span></span>
<span id="cb12-23"><a href="#cb12-23" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"Creating backup..."</span></span>
<span id="cb12-24"><a href="#cb12-24" aria-hidden="true"></a><span class="va">BACKUP_FILE=</span><span class="st">"</span><span class="va">$BACKUP_DIR</span><span class="st">/pre-migration-</span><span class="va">$(</span><span class="fu">date</span> +%Y%m%d-%H%M%S<span class="va">)</span><span class="st">.sql.gz"</span></span>
<span id="cb12-25"><a href="#cb12-25" aria-hidden="true"></a><span class="ex">wp</span> db export <span class="st">"</span><span class="va">$BACKUP_FILE</span><span class="st">"</span></span>
<span id="cb12-26"><a href="#cb12-26" aria-hidden="true"></a></span>
<span id="cb12-27"><a href="#cb12-27" aria-hidden="true"></a><span class="va">BACKUP_SIZE=$(</span><span class="fu">stat</span> -c%s <span class="st">"</span><span class="va">$BACKUP_FILE</span><span class="st">"</span><span class="va">)</span></span>
<span id="cb12-28"><a href="#cb12-28" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$BACKUP_SIZE</span><span class="st">"</span> <span class="ot">-lt</span> 1000<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb12-29"><a href="#cb12-29" aria-hidden="true"></a>    <span class="ex">log</span> <span class="st">"ERROR: Backup too small, aborting"</span></span>
<span id="cb12-30"><a href="#cb12-30" aria-hidden="true"></a>    <span class="bu">exit</span> 1</span>
<span id="cb12-31"><a href="#cb12-31" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb12-32"><a href="#cb12-32" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"✓ Backup created: </span><span class="va">$BACKUP_FILE</span><span class="st">"</span></span>
<span id="cb12-33"><a href="#cb12-33" aria-hidden="true"></a></span>
<span id="cb12-34"><a href="#cb12-34" aria-hidden="true"></a><span class="co"># Dry-run validation</span></span>
<span id="cb12-35"><a href="#cb12-35" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"Validating replacements..."</span></span>
<span id="cb12-36"><a href="#cb12-36" aria-hidden="true"></a><span class="kw">if</span> ! <span class="ex">wp</span> search-replace <span class="st">"</span><span class="va">$SOURCE_URL</span><span class="st">"</span> <span class="st">"</span><span class="va">$TARGET_URL</span><span class="st">"</span> --dry-run --report <span class="op">&amp;&gt;</span> /dev/null<span class="kw">;</span> <span class="kw">then</span></span>
<span id="cb12-37"><a href="#cb12-37" aria-hidden="true"></a>    <span class="ex">log</span> <span class="st">"ERROR: Dry-run failed"</span></span>
<span id="cb12-38"><a href="#cb12-38" aria-hidden="true"></a>    <span class="bu">exit</span> 1</span>
<span id="cb12-39"><a href="#cb12-39" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb12-40"><a href="#cb12-40" aria-hidden="true"></a></span>
<span id="cb12-41"><a href="#cb12-41" aria-hidden="true"></a><span class="co"># Count expected replacements</span></span>
<span id="cb12-42"><a href="#cb12-42" aria-hidden="true"></a><span class="va">REPLACEMENTS=$(</span><span class="ex">wp</span> search-replace <span class="st">"</span><span class="va">$SOURCE_URL</span><span class="st">"</span> <span class="st">"</span><span class="va">$TARGET_URL</span><span class="st">"</span> --dry-run --report <span class="kw">|</span> <span class="fu">grep</span> -c <span class="st">"</span><span class="va">$SOURCE_URL</span><span class="st">"</span> <span class="kw">||</span> <span class="fu">true</span><span class="va">)</span></span>
<span id="cb12-43"><a href="#cb12-43" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"Found </span><span class="va">$REPLACEMENTS</span><span class="st"> occurrences to replace"</span></span>
<span id="cb12-44"><a href="#cb12-44" aria-hidden="true"></a></span>
<span id="cb12-45"><a href="#cb12-45" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$REPLACEMENTS</span><span class="st">"</span> <span class="ot">-eq</span> 0<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb12-46"><a href="#cb12-46" aria-hidden="true"></a>    <span class="ex">log</span> <span class="st">"WARNING: No replacements found, check URLs"</span></span>
<span id="cb12-47"><a href="#cb12-47" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb12-48"><a href="#cb12-48" aria-hidden="true"></a></span>
<span id="cb12-49"><a href="#cb12-49" aria-hidden="true"></a><span class="co"># Execute replacement</span></span>
<span id="cb12-50"><a href="#cb12-50" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"Executing search-replace..."</span></span>
<span id="cb12-51"><a href="#cb12-51" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"</span><span class="va">$SOURCE_URL</span><span class="st">"</span> <span class="st">"</span><span class="va">$TARGET_URL</span><span class="st">"</span> --report</span>
<span id="cb12-52"><a href="#cb12-52" aria-hidden="true"></a></span>
<span id="cb12-53"><a href="#cb12-53" aria-hidden="true"></a><span class="co"># Also replace without protocol</span></span>
<span id="cb12-54"><a href="#cb12-54" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">"//staging.example.com"</span> <span class="st">"//example.com"</span></span>
<span id="cb12-55"><a href="#cb12-55" aria-hidden="true"></a></span>
<span id="cb12-56"><a href="#cb12-56" aria-hidden="true"></a><span class="co"># Update options directly</span></span>
<span id="cb12-57"><a href="#cb12-57" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"Updating WordPress options..."</span></span>
<span id="cb12-58"><a href="#cb12-58" aria-hidden="true"></a><span class="ex">wp</span> option update home <span class="st">"</span><span class="va">$TARGET_URL</span><span class="st">"</span></span>
<span id="cb12-59"><a href="#cb12-59" aria-hidden="true"></a><span class="ex">wp</span> option update siteurl <span class="st">"</span><span class="va">$TARGET_URL</span><span class="st">"</span></span>
<span id="cb12-60"><a href="#cb12-60" aria-hidden="true"></a></span>
<span id="cb12-61"><a href="#cb12-61" aria-hidden="true"></a><span class="co"># Verify replacements</span></span>
<span id="cb12-62"><a href="#cb12-62" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"Verifying replacements..."</span></span>
<span id="cb12-63"><a href="#cb12-63" aria-hidden="true"></a><span class="va">REMAINING=$(</span><span class="ex">wp</span> search-replace <span class="st">"</span><span class="va">$SOURCE_URL</span><span class="st">"</span> <span class="st">"</span><span class="va">$TARGET_URL</span><span class="st">"</span> --dry-run --report <span class="kw">|</span> <span class="fu">grep</span> -c <span class="st">"</span><span class="va">$SOURCE_URL</span><span class="st">"</span> <span class="kw">||</span> <span class="fu">true</span><span class="va">)</span></span>
<span id="cb12-64"><a href="#cb12-64" aria-hidden="true"></a></span>
<span id="cb12-65"><a href="#cb12-65" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="st">"</span><span class="va">$REMAINING</span><span class="st">"</span> <span class="ot">-gt</span> 0<span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb12-66"><a href="#cb12-66" aria-hidden="true"></a>    <span class="ex">log</span> <span class="st">"WARNING: </span><span class="va">$REMAINING</span><span class="st"> occurrences still remain"</span></span>
<span id="cb12-67"><a href="#cb12-67" aria-hidden="true"></a><span class="kw">else</span></span>
<span id="cb12-68"><a href="#cb12-68" aria-hidden="true"></a>    <span class="ex">log</span> <span class="st">"✓ All occurrences replaced"</span></span>
<span id="cb12-69"><a href="#cb12-69" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb12-70"><a href="#cb12-70" aria-hidden="true"></a></span>
<span id="cb12-71"><a href="#cb12-71" aria-hidden="true"></a><span class="co"># Clear caches</span></span>
<span id="cb12-72"><a href="#cb12-72" aria-hidden="true"></a><span class="ex">wp</span> cache flush</span>
<span id="cb12-73"><a href="#cb12-73" aria-hidden="true"></a><span class="ex">wp</span> rewrite flush</span>
<span id="cb12-74"><a href="#cb12-74" aria-hidden="true"></a></span>
<span id="cb12-75"><a href="#cb12-75" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"=== Migration Complete ==="</span></span>
<span id="cb12-76"><a href="#cb12-76" aria-hidden="true"></a><span class="ex">log</span> <span class="st">"Rollback backup: </span><span class="va">$BACKUP_FILE</span><span class="st">"</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="rollback-procedure">Rollback Procedure</h4>



<div class="sourceCode" id="cb13">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true"></a><span class="co">#!/bin/bash</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true"></a><span class="co"># rollback-migration.sh</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true"></a></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true"></a><span class="va">BACKUP_FILE=</span><span class="st">"</span><span class="va">$1</span><span class="st">"</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true"></a></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="ot">-z</span> <span class="st">"</span><span class="va">$BACKUP_FILE</span><span class="st">"</span><span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Usage: </span><span class="va">$0</span><span class="st"> &lt;backup-file.sql.gz&gt;"</span></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true"></a>    <span class="bu">exit</span> 1</span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true"></a></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true"></a><span class="kw">if</span><span class="bu"> [</span> <span class="ot">!</span> <span class="ot">-f</span> <span class="st">"</span><span class="va">$BACKUP_FILE</span><span class="st">"</span><span class="bu"> ]</span>; <span class="kw">then</span></span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"ERROR: Backup file not found: </span><span class="va">$BACKUP_FILE</span><span class="st">"</span></span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true"></a>    <span class="bu">exit</span> 1</span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true"></a></span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"Rolling back to: </span><span class="va">$BACKUP_FILE</span><span class="st">"</span></span>
<span id="cb13-17"><a href="#cb13-17" aria-hidden="true"></a><span class="bu">read</span> -p <span class="st">"This will overwrite current database. Continue? (y/n) "</span> -n 1 -r</span>
<span id="cb13-18"><a href="#cb13-18" aria-hidden="true"></a><span class="bu">echo</span></span>
<span id="cb13-19"><a href="#cb13-19" aria-hidden="true"></a></span>
<span id="cb13-20"><a href="#cb13-20" aria-hidden="true"></a><span class="kw">if [[</span> <span class="ot">!</span> <span class="va">$REPLY</span> =~ ^[Yy]$<span class="kw"> ]]</span>; <span class="kw">then</span></span>
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Rollback cancelled"</span></span>
<span id="cb13-22"><a href="#cb13-22" aria-hidden="true"></a>    <span class="bu">exit</span> 0</span>
<span id="cb13-23"><a href="#cb13-23" aria-hidden="true"></a><span class="kw">fi</span></span>
<span id="cb13-24"><a href="#cb13-24" aria-hidden="true"></a></span>
<span id="cb13-25"><a href="#cb13-25" aria-hidden="true"></a><span class="co"># Restore database</span></span>
<span id="cb13-26"><a href="#cb13-26" aria-hidden="true"></a><span class="ex">wp</span> db import <span class="st">"</span><span class="va">$BACKUP_FILE</span><span class="st">"</span></span>
<span id="cb13-27"><a href="#cb13-27" aria-hidden="true"></a></span>
<span id="cb13-28"><a href="#cb13-28" aria-hidden="true"></a><span class="co"># Flush caches</span></span>
<span id="cb13-29"><a href="#cb13-29" aria-hidden="true"></a><span class="ex">wp</span> cache flush</span>
<span id="cb13-30"><a href="#cb13-30" aria-hidden="true"></a><span class="ex">wp</span> rewrite flush</span>
<span id="cb13-31"><a href="#cb13-31" aria-hidden="true"></a></span>
<span id="cb13-32"><a href="#cb13-32" aria-hidden="true"></a><span class="bu">echo</span> <span class="st">"✓ Rollback complete"</span></span></code></pre>
</div>



<h3 class="wp-block-heading" id="troubleshooting">Troubleshooting Search-Replace</h3>



<p>Fix common search-replace issues.</p>



<h4 class="wp-block-heading" id="urls-not-changing">URLs Not Changing</h4>



<div class="sourceCode" id="cb14">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true"></a><span class="co"># Check current URLs in database</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'oldsite.com'</span> <span class="st">'oldsite.com'</span> --dry-run --report <span class="kw">|</span> <span class="fu">head</span> -20</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true"></a></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true"></a><span class="co"># Try all URL variations</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'http://oldsite.com'</span> <span class="st">'https://newsite.com'</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'https://oldsite.com'</span> <span class="st">'https://newsite.com'</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'http://www.oldsite.com'</span> <span class="st">'https://newsite.com'</span></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'//oldsite.com'</span> <span class="st">'//newsite.com'</span></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true"></a></span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true"></a><span class="co"># Force update options</span></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true"></a><span class="ex">wp</span> option update home <span class="st">'https://newsite.com'</span></span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true"></a><span class="ex">wp</span> option update siteurl <span class="st">'https://newsite.com'</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="serialization-errors">Serialization Errors</h4>



<div class="sourceCode" id="cb15">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true"></a><span class="co"># Check for serialization issues</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --precise</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true"></a></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true"></a><span class="co"># Skip problematic tables</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> --skip-tables=wp_options</span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true"></a></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true"></a><span class="co"># Replace table by table</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true"></a><span class="kw">for</span> <span class="ex">TABLE</span> in <span class="va">$(</span><span class="ex">wp</span> db tables --format=csv<span class="va">)</span><span class="kw">;</span> <span class="kw">do</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true"></a>    <span class="bu">echo</span> <span class="st">"Processing: </span><span class="va">$TABLE</span><span class="st">"</span></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true"></a>    <span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> <span class="st">"</span><span class="va">$TABLE</span><span class="st">"</span> --dry-run</span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true"></a><span class="kw">done</span></span></code></pre>
</div>



<h4 class="wp-block-heading" id="performance-issues">Performance Issues</h4>



<div class="sourceCode" id="cb16">
<pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true"></a><span class="co"># Large databases may timeout, increase PHP limits</span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true"></a><span class="ex">php</span> -d memory_limit=512M wp search-replace <span class="st">'old'</span> <span class="st">'new'</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true"></a></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true"></a><span class="co"># Process tables individually for very large databases</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> wp_posts</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> wp_postmeta</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true"></a><span class="ex">wp</span> search-replace <span class="st">'old'</span> <span class="st">'new'</span> wp_options</span></code></pre>
</div>



<h3 class="wp-block-heading" id="next-steps">Next Steps</h3>



<p>You now have professional WordPress search-replace skills for safe database migrations.</p>



<h4 class="wp-block-heading" id="recommended-learning-path">Recommended Learning Path</h4>



<p><strong>Week 1</strong>: Basic replacements</p>



<ul class="wp-block-list">
<li>Practice dry-run workflows</li>



<li>Test domain changes on staging</li>



<li>Learn serialization concepts</li>
</ul>



<p><strong>Week 2</strong>: Advanced techniques</p>



<ul class="wp-block-list">
<li>Master regex patterns</li>



<li>Handle complex migrations</li>



<li>Build verification scripts</li>
</ul>



<p><strong>Week 3</strong>: Production migrations</p>



<ul class="wp-block-list">
<li>Create complete migration workflows</li>



<li>Implement rollback procedures</li>



<li>Document migration playbooks</li>
</ul>



<p><strong>Week 4</strong>: Automation</p>



<ul class="wp-block-list">
<li>Build migration scripts</li>



<li>Add validation checks</li>



<li>Automate testing</li>
</ul>



<h4 class="wp-block-heading" id="advanced-topics">Advanced Topics</h4>



<ol class="wp-block-list">
<li><strong><a href="#">Multisite Search-Replace</a></strong> &#8211; Network-wide replacements</li>



<li><strong><a href="#">Large Database Migrations</a></strong> &#8211; Handle millions of records</li>



<li><strong><a href="#">Custom Table Migrations</a></strong> &#8211; Plugin-specific data</li>
</ol>



<h4 class="wp-block-heading" id="get-more-resources">Get More Resources</h4>



<p><strong><a href="#">Download migration scripts</a></strong> including:</p>



<ul class="wp-block-list">
<li>Complete migration automation</li>



<li>Rollback procedures</li>



<li>Validation checklists</li>
</ul>



<p><strong><a href="/#get-started">Join our email course</a></strong> for:</p>



<ul class="wp-block-list">
<li>Weekly WP-CLI tutorials</li>



<li>Migration best practices</li>



<li>Advanced database techniques</li>
</ul>



<h3 class="wp-block-heading" id="conclusion">Conclusion</h3>



<p>WP-CLI search-replace is the only safe way to modify WordPress database content, handling serialized data automatically while giving you complete control and visibility.</p>



<p>What we covered:</p>



<p>✅ Search-replace fundamentals with dry-run validation <br>✅ Common use cases (domain changes, HTTPS migration, paths) <br>✅ Advanced techniques (regex, table-specific, reporting) <br>✅ Safe migration workflows with backups and rollback <br>✅ Troubleshooting common search-replace issues</p>



<p>Master these techniques, and you’ll handle WordPress migrations and database modifications with confidence—whether changing domains, updating URLs, or migrating content.</p>



<p><strong>Ready for more?</strong> Learn <a href="#">WordPress database optimization</a> or <a href="#">advanced WP-CLI automation</a>.</p>



<p><strong>Questions about WP-CLI search-replace?</strong> Drop a comment below!</p>



<p><strong>Found this helpful?</strong> Share with other WordPress developers.</p>
<p>The post <a href="https://wpclimastery.com/blog/wp-cli-search-replace-safe-database-modifications-for-wordpress-migration/">WP-CLI Search-Replace: Safe Database Modifications for WordPress Migration</a> appeared first on <a href="https://wpclimastery.com">WP-CLI Mastery</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
